2011-02-01 139 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'; 
相關問題