Today we have come with a solution to the problem of transferring files from another host. Generally when you download the files to your computer and later upload the files to a new server require too much time. Moreover, your WIFI/router or mobile data is wasted. To overcome this issue, we are providing you with the PHP script to remotely copy files within your web hosting. Copying files from one server to server is faster than uploading from your computer.
Server to Server File Transfer PHP Script Installation
Follow the below steps to install the PHP script in your hosting. It’s a simple script consists of two files. If you can’t implement, we will provide the download links at the bottom.
Step 1: Create Destination/Installation Folder
First, decide where you want to download the files. It can be the root directory i.e. public_html or /download something else.
Step 2: Installing the Script
Create a filename called, “transfer.html” on the destination folder or on your Desktop and paste the following code-
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Transfer File PHP - Transfer file from another server (php script)</title> <style type="text/css"> body{ font-family: arial; font-size: 14px; padding: 0; margin: 0; text-align: center; } h3{ text-align: center; } .container{ width: 600px; margin: 100px auto 0 auto; max-width: 100%; } label{ font-weight: bold; margin: 10px 0; } input[type="text"]{ border: 1px solid #eee; padding: 10px; display: block; margin: 10px auto; } input[type="submit"]{ padding: 10px 20px; display: block; margin: 10px auto; border: 2px solid green; background: #fff; } .copyright{ position: fixed; bottom:0; background: #333; color: #fff; width: 100%; padding: 10px 20px; text-align: center; } .copyright a{ color: #eee; } </style> </head> <body> <div class="container"> <h3>Transfer File PHP - Transfer file from another server (php script)</h3> <form action="copy.php" method="post"> <label for="remote_file">Locate the File</label> <br> <input type="text" id="remote_file" name="remote_file" value="" placeholder="Enter URL of the file" /> <input type="submit" value="Transfer" /> </form> </div> </body> </html>
Now, within the same directory, create another filename called, “copy.php” and paste the below code-
<?php /** * Transfer Files Server to Server using PHP Copy * @link https://weneedwebsite.com/blog/server-to-server-remote-file-transfer/ */ /* Source File URL */ $remote_file_url = $_POST['remote_file']; /* New file name and path for this file */ $local_file = 'files.zip'; /* Copy the file from source url to server */ $copy = copy( $remote_file_url, $local_file ); /* Add notice for success/failure */ if( !$copy ) { echo "Opps! Failed! Something went wrong to copy the $file...\n"; } else{ echo "Hurraaah! File successly Copied as files.zip ...\n"; } ?>
Step 3: Transfer the Files
You have successfully installed the PHP file transfer script. Now, to transfer the file locate the filename transfer.html. The window for transferring files looks like below-
Now, on the form, enter your remote filename. Then click on Transfer.
After a successful file copied it will display a dialogue as,
“Hurraaah! File successfully Copied as files.zip … “.
If it fails then say as,
“Oops! Failed! Something went wrong to copy the … “.
Download the ScriptImportant Note:
Now rename the file called “files.zip” to the previous filename extension, as we have just copied the file from a remote location to the local folder and haven’t compressed the file.
The PHP file transfer script here copies the files from the remote server only a single file at once. So, you must combine those files to download at once. You can learn below the articles for your help.
Leave a Reply