I need a download a file to remote server. But i can't do it with curl in php. The code is:
$ch = curl_init($source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8096);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
var_dump(curl_exec($ch));
print_r(curl_getinfo($ch));
die;
The result is:
string(0) ""
Array
(
[url] => http://example.com/example.zip
[content_type] =>
[http_code] => 204
[header_size] => 213
[request_size] => 118
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.180951
[namelookup_time] => 0.012276
[connect_time] => 0.105478
[pretransfer_time] => 0.105523
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 1.18091
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 104.79.246.86
[certinfo] => Array
(
)
[primary_port] => 80
[local_ip] => 192.168.0.14
[local_port] => 46676
)
The file download normaly in browser. what is wrong?. Sorry for my English and thanks for your help
A 204 status means the server is choosing to not return any content, just updated meta data. It may be doing that because it is checking for what kind of browser you are using and isn't setup to respond to curl.
Check out How to disguise your PHP script as a browser? for how to make your script look like a browser.
BTW, you only need to set CURLOPT_RETURNTRANSFER once. Setting it to true or 1 will give you the same result.