Transfer Files from Server/URL to Server Using PHP Scripts | Tips and Tricks

0
403

In this tutorial we are going to transfer a file from remote server to a specific location in our destination server. You can use this simple PHP script to transfer files from one server to another server.

To do that, follow the instructions:

First, create a php file in the destination server and load the file once in your browser. For example you add this code in http://destination-url/upload.php and in upload.php you add this php code:

  define('BUFSIZ', 4095);
//URL of your file
  $url = 'https://schlaffass.at/wp-content/uploads/2019/09/themeforest-tjZxBPm9-kallyas-responsive-multipurpose-wordpress-theme-wordpress-theme.zip';
  $rfile = fopen($url, 'r');
  $lfile = fopen(basename($url), 'w');
  while(!feof($rfile))
    fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
  fclose($rfile);
  fclose($lfile);
  echo "Done";

In this script specify the file url from the remote server into $url variable and save the file.

Then load the php file from your web browser. File transfer rate depends on your file size and server configuration. 

If you got “Fatal error: Maximum execution time of XX seconds exceeded” this type of error then add the following code at the top of your scripts.

ini_set('max_execution_time', 0);

For example:

  ini_set('max_execution_time', 0); //infinite execution time of this script.
  define('BUFSIZ', 4095);
//URL of your file
  $url = 'https://schlaffass.at/wp-content/uploads/2019/09/themeforest-tjZxBPm9-kallyas-responsive-multipurpose-wordpress-theme-wordpress-theme.zip';
  $rfile = fopen($url, 'r');
  $lfile = fopen(basename($url), 'w');
  while(!feof($rfile))
    fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
  fclose($rfile);
  fclose($lfile);
  echo "Done";

LEAVE A REPLY

Please enter your comment!
Please enter your name here