2010-08-11 130 views
0

我最近改變了服務器,並且我的一個腳本沒有在新服務器上運行,因爲fopen沒有啓用?轉換fopen捲曲?

是否可以改變下面的代碼來改爲使用CURL函數?

希望有人能幫助!

<?php 
$postToFileName = 'http://www.somesite.com/postfile.aspx'; 
$postArr = array(

'NM' => $row['Lead_Name'], 

'EM' => $row['Lead_Email'], 

'PH' => $row['Lead_Tel'], 

); 

$opts = array(

'http'=>array(

'method' => 'POST', 

'header' => "Content-type: application/x-www-form-urlencoded\r\n", 

'content' => http_build_query($postArr) 

) 

); 

$context = stream_context_create($opts); 

$fp = fopen($postToFileName, 'r', false, $context); 

$returnedMessage = ''; 

while (!feof($fp)) { 

$returnedMessage .= fgets($fp); 

} 

fclose($fp); 

if ($returnedMessage == '') { 

$returnedMessage = 'No Message'; 

} else if (strlen($returnedMessage) > 250) { 

$returnedMessage = substr($returnedMessage,0,250); 

} 

$returnedMessage = preg_replace("/[\r\n]/", '', $returnedMessage); 

$returnedMessage = mysql_real_escape_string($returnedMessage, $sql); 

$q = "UPDATE leads SET Data_Sent = '$returnedMessage' WHERE Lead_ID = $id"; 

mysql_query($q, $sql); 

array_push($leadsSent, $id); 

} 

} 

mysql_close($sql); 

return $leadsSent; 

} 



?> 

回答

0

當然。它應該看起來像這樣(當然沒有測試,可能需要一些小的更改):

$postToFileName = 'http://www.somesite.com/postfile.aspx'; 
$postArr = array(
    'NM' => $row['Lead_Name'], 
    'EM' => $row['Lead_Email'], 
    'PH' => $row['Lead_Tel'], 
); 

$ch = curl_init($postToFileName); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArr); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$returnedMessage = curl_exec($ch); 
curl_close($ch);