cURL将文件上载到MS Windows上的远程服务器

Dad*_*dor 5 php linux windows upload curl

当我使用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; // << on Windows empty result
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

PHP 5.3

Windows 7 - 不工作,Ubuntu Linux 10.10 - 工作

Ter*_*den 4

如果您使用的是 Windows,您的文件路径分隔符将不是\Linux 风格/

一件明显值得尝试的事情是

$post=array('image'=>'@'.getcwd().'images\image.jpg');
Run Code Online (Sandbox Code Playgroud)

看看是否有效。

如果你想让你的脚本可移植,以便它可以在 Windows 或 Linux 上运行,你可以使用PHP 的预定义常量 DIRECTORY_SEPARATOR

$post=array('image'=>'@'.getcwd().'images' . DIRECTORY_SEPARATOR .'image.jpg');
Run Code Online (Sandbox Code Playgroud)