【问题标题】:error when upload file to remote server (Windows, cURL)将文件上传到远程服务器时出错(Windows、cURL)
【发布时间】:2011-02-01 22:52:36
【问题描述】:

当我使用 linux 时,这个脚本可以工作。但是,如果我使用 Windows,那么脚本将无法正常工作。脚本:

$url="http://site.com/upload.php";
$post=array('image'=>'@'.getcwd().'\\images\\image.jpg');
$this->ch=curl_init();
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 30);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
$body = curl_exec($this->ch);
echo $body;

日志错误:

* 创建表单数据失败

文件存在且可读。

【问题讨论】:

  • 不是答案(也不是可能的解决方案),但顺便说一句,在提到路径名时我会使用DIRECTORY_SEPARATOR)。 (或者至少,坚持使用正斜杠 (/),因为 windows 无所谓,但 *nix 介意)

标签: php windows file curl upload


【解决方案1】:

执行时打印出的内容:

echo $post['image'];

它是否打印出正确的文件路径? 您是作为 CLI 运行它还是在 Windows 上安装 Apache? 您可能必须使用:

$post['image'] = '@'.dirname(__FILE__).'\\images\\image.jpg';

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多