This thread is both a code snippet and a question.

Lets start with the code:
PHP Code: 
$url "http://downloadwebsite.com/file_you_are_going_to_download.rar";
$out fopen("./".trim(basename($url)), 'wb+'); //Opens the temp file in the local directory of your server, same filename as the file you are downloading
$ch curl_init(); //initialize curl 
curl_setopt($chCURLOPT_FILE$out);  //Set it to download the content to the file created previously
curl_setopt($chCURLOPT_HEADER0); //Depending on the website you are downloading from there are headers that need to be sent
curl_setopt($chCURLOPT_URL$url); //Set the url you want to start curling :P
curl_exec($ch); //Do the magic
curl_close($ch); //Close the magic
fclose($out); //Close the downloaded file properly 
Now an issue:
On a server from a KWWH member this worked perfectly, but now all of a sudden, instead of downloading the file to the server, it displays the contents of the file in the browser, any ideas why this is happening?

Thanks all
Whoo Reviewed by Whoo on . [PHP] Downloading a file with cURL This thread is both a code snippet and a question. Lets start with the code: $url = "http://downloadwebsite.com/file_you_are_going_to_download.rar"; $out = fopen("./".trim(basename($url)), 'wb+'); //Opens the temp file in the local directory of your server, same filename as the file you are downloading $ch = curl_init(); //initialize curl curl_setopt($ch, CURLOPT_FILE, $out); //Set it to download the content to the file created previously curl_setopt($ch, CURLOPT_HEADER, 0); Rating: 5