PHP script for fetching 4GB file from URL to your Server

       Below is the php script for fetching 4GB file from URL to your Server. The ini_set(‘upload_max_filesize’, ‘5000M’), ini_set(‘post_max_size’, ‘5000M’) statements specifies the maximum size of the data to fetch/upload by the script, if we want to fetch file of size 10GB then we can easily do so simply by changing the 2nd parameter(size in megabytes) of this calls. Next important setting is set_time_limit (24 * 60 * 60) which specifies the maximum time in seconds for running this script  ( as downloading file size is more it takes more time). Note that this time totally depends on the size of the file you want to fetch and the network speed of your server.
         If you are thinking of running this script on general hosting service (where network speed is less) then it requires more time to execute (may be in Hrs) so, accordingly  you should set execution time limit. I had tested it on my local machine as well as on hosting service although it takes more CPU resource but works fine. I recommend to use it only for personal use. Its totally inefficient for bulk fetches, most of hosting services do not recommend such scripts because it simply  overloads their resources.

<html><head><title>BIG UPLOADER</title></head><body><center></a></br</p></br</p><form method="post"><input name="url" size="50" /><input name="submit" type="submit" /></form><?phpini_set('upload_max_filesize', '5000M');ini_set('post_max_size', '5000M');ini_set('max_input_time', 24 * 60 * 60);// maximum execution time in secondsset_time_limit (24 * 60 * 60);if (!isset($_POST['submit'])) die();// folder to save downloaded files to. must end with slash$destination_folder = 'files/';$url = $_POST['url'];$newfname = $destination_folder . basename($url);$file = fopen ($url, "rb");if ($file) {  $newf = fopen ($newfname, "wb");  if ($newf)  while(!feof($file)) {    fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );  }}if ($file) {  fclose($file);}if ($newf) {  fclose($newf);}?></center></body></html>



Popular posts from this blog

MATLAB code for Circular Convolution using Matrix method

Positive number pipe in angular 2+