2012-06-15 60 views
0

因爲我無法獲得所需要的pecl_http擴展,我需要改變這段代碼更改此代碼,使用捲曲

<?php 
    $files = array(
     array(
      'name' => 'torrent',   // Don't change 
      'type' => 'application/x-bittorrent', 
      'file' => 'my.torrent'   // Full path for file to upload 
     ) 
    ); 

    $http_resp = http_post_fields('http://torcache.net/autoupload.php', array(), $files); 
    $tmp = explode("\r\n", $http_resp); 
    $infoHash = substr($tmp[count($tmp) - 1], 0, 40); 
    unset($tmp, $http_resp, $files); 
?> 

使用捲曲相反,這裏是我迄今爲止;

<?php 
    $files = array(
     array(
      'name' => 'torrent',   // Don't change 
      'type' => 'application/x-bittorrent', 
      'file' => '0-273-70244-0.pdf.torrent'   // Full path for file to upload 
     ) 
    ); 





$ch = curl_init();     //this part we set up curl 
curl_setopt($ch, CURLOPT_URL,'http://torcache.net/autoupload.php'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $files); 
$xml_response = curl_exec($ch); 
curl_close($ch); 
return $xml_response; 
$infoHash= substr($xml_response,0,40); 

然而事情是錯誤的,因爲該字符串沒有被顯示的上傳後,我只是得到了一個空白的網頁

什麼想法?

回答

0

如果您想從功能中傳回數據,則只需使用return。在你的代碼中,你沒有這樣做,所以返回的結果是儘早結束文檔的處理。

刪除退貨應該可以解決您的問題。

+0

我仍然收到一個空白的網頁, –