Task: download the file from another server, specifying its name in the request parameter ( http://www.site.com/download.aspx?filename=filename.dot )
I use cURL
$url ='http://www.site.com/download.aspx?filename=filename.dot'; $curl_handle=curl_init(); curl_setopt($curl_handle, CURLOPT_URL,$url); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.2; rv:6.0.2) Gecko/20100101 Firefox/6.0.2'); $fileString = curl_exec($curl_handle); print_r(curl_getinfo($curl_handle)); curl_close($curl_handle);
I receive:
Array ( [url] => http://www.site.com/download.aspx?filename=filename.dot [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 29.999874 [namelookup_time] => 9.7E-5 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => [certinfo] => Array ( ) [primary_port] => 0 [local_ip] => [local_port] => 0 )
Although if you open this URL in the browser - then it downloads the file. file_get_contents () doesn't work either.
What could be the problem?
HTTP/1.1 404 Not Found
- Alexey ShimanskyCURLOPT_TIMEOUT
/CURLOPT_CONNECTTIMEOUT
, or use0
. - hindmost