dongpiaozhao6836 2012-06-15 11:57
浏览 90
已采纳

curl不循环遍历此数组

<?php
// open the current directory
$dhandle = opendir('.');
// define an array to hold the files
$files = array();

if ($dhandle) {
   // loop through all of the files
   while (false !== ($fname = readdir($dhandle))) {
      // if the file is not this file, and does not start with a '.' or '..',
      // then store it for later display
      if (($fname != 'index.htm') && ($fname != 'torcache.php')&& ($fname != 'error_log') && (substr($fname, 0, 5) != 'other') && (substr($fname, 0, 2) != 'dd') &&
          ($fname != basename($_SERVER['PHP_SELF']))) {
          // store the filename
          $files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
      }
   }
   // close the directory
   closedir($dhandle);
}


function curl_upload($url,$fileFormAttribute,$file){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch,CURLOPT_REFERER, 'https://torcache.net/');
        curl_setopt($ch,CURLOPT_ENCODING,"gzip");
        curl_setopt($ch, CURLOPT_POST, true);
        $post = array($fileFormAttribute=>"@".$file);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        $response = curl_exec($ch);
        return $response;
}
foreach( $files as $fname )
{
error_reporting(E_ALL);


$upload_result = curl_upload('http://torcache.net/autoupload.php','torrent','public_html/download_folder/'.$files[0]);
}
var_dump($upload_result);
?>

when i run this script it only posts the first item in the array instead of looping through the entire array what am i doing wrong? I want to have it loop through all the files in the dir then post them to torcache and then give me back the string;

展开全部

  • 写回答

1条回答 默认 最新

  • dotcraq3249 2012-06-15 12:00
    关注

    Shouldn't the .$files[0] be just $fname in your fourth-from-last line? Like this:

    $upload_result = curl_upload('http://...','torrent','public_html/download_folder/'.$fname);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 传人记程序做的plc 485从机程序该如何写
  • ¥15 已知手指抓握过程中掌指关节、手指各关节和指尖每一帧的坐标,用贝塞尔曲线可以拟合手指抓握的运动轨迹吗?
  • ¥50 libwebsockets 如何添加其他socket事件回调
  • ¥50 实现画布拖拽算子排布,通过flink实现算子编排计算,请提供思路
  • ¥15 esium自定义材质拉伸问题
  • ¥15 cmake+mingw使用<mysqlx/xdevapi.h>报错
  • ¥15 eNSP中防火墙的使用
  • ¥15 关于#mlnet#的问题:mlnet相关请求(语言-c#)
  • ¥15 lvgl7.11怎么做出文字被选中的效果
  • ¥50 如何快速查看手机目标app的主要服务器ip
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部