Sometimes you might need to copy a big file to your website. Usually, you would simply upload it with an FTP client, but when you have the file already on another website, it would be much faster to just copy the file directly from your another website straight to your website with a direct connection. As well, you might need to extract the file after it has been copied. I’ll consider an example where you have to copy the WordPress web software zip file to your website. The script here is written with PHP and runs on a Linux platform. Before you run the script, the destination folder on your website must have the suitable CHMOD, 755 would be enough.
Do the following steps to create the script file and copy the ZIP file to your website:
- Create a file and name it copy.php
- Open the file in a text editor and copy the following script:
<?php if(!copy("http://wordpress.org/latest.zip", "wordpress.zip")) { echo("Failed to copy the file."); } ; ?> - As you can see in the script, there is a source URL (http://wordpress.org/latest.zip) of the file and a destination path and file name (wordpress.zip , in same directory). Change these according to your input.
- Then save the file.
- Upload copy.php using your FTP client to the destination folder.
- Now, using your web browser, access the copy.php file so that the script runs and copies the file. For example, if you uploaded the file to the root directory, use www.yourdomain.com/copy.php
- If the script runs successfully, the wordpress.zip file should be there in the destination directory.
Also typically, you might need to extract this file. I’ll show you how to do that if you had a web hosting account that uses cPanel. HostGator has such platform for example. Click here to see how to extract a zip archive file with cPanel
Want to get updates for new posts? Subscribe to my RSS feed and follow me on twitter :)
You can also get the ITfall blog updates by Email.
And don't forget to share this post and leave a comment ;)
4 Comments
I tried this several times with several different combinations of source and destination but it failed each time. Wondering how the browser knows the login and password for permissions to write to the destination location.
I tried this several times with several different combinations of source and destination but it failed each time. Wondering how the browser knows the login and password for permissions to write to the destination location.
Update: Changed destination folder permissions to 777 and like magic – it worked like a charm. Just need to remember to change back to 755 when done copying.
I can copy .php but it is converted into html. What i need is php code uploaded on another website..
only get 150 mb maximum online upload how get more than 5gb ????
One Trackback
[...] because of this fault so no customer will or can be harmed with it. But guess what? Check this : Copy File from Website to Website with a PHP Script – ITfall Now look at the code I posted and you will see it is almost IDENTICAL with NO wget parameter in [...]