When I use linux and try upload file to remote server using this script then all is well. But if i use Windows then script not working. Script:
$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
What am I doing wrong?
PHP 5.3
Windows 7 - not working, Ubuntu Linux 10.10 - working
If you are using Windows, your file path separator will be \
not the Linux style /
.
One obvious thing to try is
$post=array('image'=>'@'.getcwd().'images\image.jpg');
And see if that works.
If you want to make your script portable so it will work on with Windows or Linux, you can use PHP's predefined constant DIRECTORY_SEPARATOR
$post=array('image'=>'@'.getcwd().'images' . DIRECTORY_SEPARATOR .'image.jpg');
Theoretically, your code should not work(i mean upload) in any, unix or windows. Consider this portion from your code:
'image'=>'@'.getcwd().'images/image.jpg'
In windows getcwd()
returns F:\Work\temp
In Linux It returns /root/work/temp
So, your above code will compile like below:
Windows: 'image'=>'@F:\Work\tempimages/image.jpg'
Linux: 'image'=>'@/root/work/tempimages/image.jpg'
Since you mentioned it worked for you in linux, which means /root/work/tempimages/image.jpg
somehow existed in your filesystem.
My PHP version:
Linux: PHP 5.1.6
Windows: PHP 5.3.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With