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?

  • You got the info, but you do not save the file ..... can you try it? expange.ru/e/… .... by your link HTTP/1.1 404 Not Found - Alexey Shimansky
  • Apparently the request is terminated by timeout. Try increasing the values ​​of the CURLOPT_TIMEOUT / CURLOPT_CONNECTTIMEOUT , or use 0 . - hindmost
  • @hindmost Internal Server Error and log empty - vsb95
  • @ Alexey Shimanskiy Internal Server Error and the log is empty - vsb95

1 answer 1

Problems may be different, for starters, try to view the curl errors:

 //... $fileString = curl_exec($curl_handle); echo curl_errno($curl_handle); echo curl_error($curl_handle); //... 

but, most likely, it is not downloaded due to the internal implementation of file sharing, since link to the file is not direct.