2011-02-01 151 views
1

当我使用linux这个脚本工作。但是如果我使用Windows,那么脚本无法工作。脚本:上传文件到远程服务器时出错(Windows,cURL)

$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; 

错误日志:

*未能创建formpost数据

文件存在并且可读。

echo $post['image']; 

是否打印出正确的文件路径:

+1

不是一个答案(也不是可能的解决方案),但作为一个在旁边,我会用[DIRECTORY_SEPARATOR(http://php.net/manual/en/dir.constants。 PHP)当提到路径名称)。 (或者至少,坚持使用正斜杠(`/`),因为窗户是冷漠的,但* nix的头脑) – 2011-02-01 22:55:10

回答

0

时,你要做的就是打印出来? 你是在Windows上运行CLI还是Apache安装? 您可能需要使用:

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