【问题标题】:Recreating http request with cURL incl. files使用 cURL 重新创建 http 请求,包括。文件
【发布时间】:2011-03-01 07:27:13
【问题描述】:

我一直从下面的代码中收到错误“创建表单发布数据失败”,同样的事情在我的本地测试服务器上完美运行,但在我的共享主机上它会抛出错误。

示例部分只是模拟使用文件和非文件数据构建数组。基本上我在这里要做的就是将相同的 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);

【问题讨论】:

  • 应该提到我正在上传一组文件(照片) - 因此循环

标签: php http curl


【解决方案1】:

一个快速的谷歌出现了这个:

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

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

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

cURL 可能不知道在哪个目录中查找$_FILES['photographs']['tmp_name'][$i]

【讨论】:

  • 我看过那个页面,并尝试添加额外的路径信息。到目前为止没有运气。
猜你喜欢
  • 1970-01-01
  • 2021-12-01
  • 2021-07-24
  • 2014-11-16
  • 1970-01-01
  • 2015-07-29
  • 1970-01-01
  • 2015-05-13
  • 1970-01-01
相关资源
最近更新 更多