使用cURL incl重新创建http请求。档

时间:2010-06-08 18:09:05

标签: php http curl

我始终从下面的代码中获得错误'创建formpost数据失败',同样的事情在我的本地测试服务器上完美运行,但在我的共享主机上它会抛出错误。

示例部分仅用于模拟使用文件和非文件数据构建阵列。基本上我在这里尝试做的就是将相同的http请求重定向到另一台服务器,但是我遇到了很多麻烦。

  $count=count($_FILES['photographs']['tmp_name']);

   $file_posts=array('samplesample' => 'ladeda');

   for($i=0;$i<$count;$i++) {
if(!empty($_FILES['photographs']['name'][$i])) {
     $fn = genRandomString();
     $file_posts[$fn] = "@".$_FILES['photographs']['tmp_name'][$i];
    }
   }

   $ch = curl_init();
   curl_setopt($ch,CURLOPT_URL,"http://myurl/wp-content/plugins/autol/rec.php");      
   curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
   curl_setopt($ch,CURLOPT_HEADER,TRUE);
   curl_setopt($ch,CURLOPT_POST,TRUE);
   curl_setopt($ch,CURLOPT_POSTFIELDS,$file_posts);
   curl_exec($ch);
   print curl_error($ch);
   curl_close($ch);

1 个答案:

答案 0 :(得分:0)

快速谷歌出现了这个:

http://www.phpfreaks.com/forums/index.php?topic=125783.0

看起来你可能需要在这一行添加一些额外的路径信息:

$file_posts[$fn] = "@".$_FILES['photographs']['tmp_name'][$i];

cURL可能无法知道在{.1}中查找哪个目录。