Do you want to download files from any another site directly to your web server or do you want to transfer files between different sites, then this script is going to help you.
Recently, I needed to shift files from my one site to another, but the problem was that the files were quite large and I wasn’t able to shift them manually by downloading and uploading, so I have decided to search a script for this work but I find it very hard to get good working piece of script. After a lot of testing, one script worked for me and now I decided to save it on my site to help others and me too in future.
Copy the code below and save it in PHP extension on your site. Replace URL _TO_DOWNLOAD with the file url you want to download, also create a new folder name UPLOADS and then run the code from the frontend.
This code will download the file in upload section after the browser loading is completed. You may need to change the extension of the downloaded file to original to use it.
<?Php
$url = "URL_TO_DOWNLOAD";
$destination = "uploads/filename";
$fp = fopen ($destination, 'w+');
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $ch, CURLOPT_FILE, $fp );
curl_exec( $ch );
curl_close( $ch );
fclose( $fp );
?>
If you have any better script or have any problem then let me know in comments.
2 Comments
Hi Hamza Ahmed. I used your script to transfer my backups from cpanel to download host. It Worked. Thanks.
Glad to know Iman.