doucepei5298 2012-06-15 05:51
浏览 41

更改此代码以使用curl

Because I cannot get the pecl_http extension that is needed, I need to change this bit of code

<?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( "
", $http_resp );
    $infoHash = substr( $tmp[count( $tmp ) - 1], 0, 40 );
    unset( $tmp, $http_resp, $files );
?>

to use curl instead, here is what i have so far;

<?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);

however something is wrong as the string is not being shown after the upload, i just get a blank webpage

any ideas?

  • 写回答

1条回答 默认 最新

  • 普通网友 2012-06-15 06:07
    关注

    You only need to use return if you want to pass back data from within a function. In your code you aren't doing that, so instead the return is ending the processing of your document early.

    Removing the return should fix your issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?