Easy Script for Downloading Files using PHP

Create a file named download.php and use the code below:

<?php
set_time_limit(0);

$url = "http://someurl/file.zip";
$filename = "file.zip";

// This is the file where we save the    information
$fp = fopen (dirname(__FILE__) . '/' . $filename, 'w+');
// Here is the file we are downloading, replace spaces with %20
$ch = curl_init(str_replace(" ","%20",$url));
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
// write curl response to file
curl_setopt($ch, CURLOPT_FILE, $fp); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// get curl response
curl_exec($ch); 
curl_close($ch);
fclose($fp);
?>

Repalce you file url with http://someurl/file.zip and the filename with file.zip.

Run the script by accessing it via browser.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.