29 May 2008

Download files from web to your hosting account (Wget in PHP)

Posted by Norman under: Guides .

While I was preparing a small guide to Magento installation for the end users, I faced a silly issue, In the guide, I’m asking the user to download 40MB of magento content to his/her computer then upload it using FTP or cPanel file manager .. silly isn’t it?

With shell root access, I’m using WGET command to get large files directly to the server, downloading 40MB takes less than 4 seconds!

In cPanel filemanager, you can extract zipped files, but you can’t download/get the file direct from the web, you need to upload it from your computer.

So to solve this issue, I have made the following PHP script, this script will allow you to get any large compressed file direct to your hosting account in an average speed of 10MB/second.

How to use it:

  1. Copy/Paste the code below to your text editor (notepad is enough)
  2. Modify the $fileToDownload  value and put the url to the file you want to download
    for example:
    $fileToDownload=’http://www.2mhost.com/web-hosting-images/2mhost.gif’;
  3. Save the file and name it whatever you want with extension .php ; For example : 2mwget.php
  4. Upload the file to any folder within your /public_html folder.
  5. Run the script from the browser and you are done, if file is big, it could take some time

The code:


<?
/* --------------------------------------------
WGETinPHP by <a href="http://www.2mhost.com">www.2mhost.com</a>
--------------------------------------------- */

// specify the file you want to download below, start with http://
$fileToDownload='http://www.2mhost.com/web-hosting-images/2mhost.gif';

// specify where you want to put it, default is '.', to put the file
// in same folder as the script.
$putFileIn='.';

// No need to edit any thing below

 $toDownload = file_get_contents($fileToDownload);
 
 if (!$toDownload) {
  die('<br>ERROR:  could not get the file, may be the file is not there.');
 }
 
 if (!file_put_contents($putFileIn.'/'.basename($fileToDownload),$toDownload)) {
   die('<br>ERROR: Got the file, but could not write it');
  } else {
   echo '<br>DONE: Download completed to '.$putFileIn.'/'.basename($fileToDownload);
 }

?>

Leave a Reply

Browse

Calendar

May 2008
M T W T F S S
« Apr   Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

Links