Easy Server File Transfer Using PHP

Sometimes we need to migrate our server. If we do it manually we need to download all files from the old server and upload to the new server. It's so painful task for us and it takes a lot of time. So that I think to make it easy I use Easy Server File Transfer method by using PHP. I use a shortcut technique for this technique reduces my time and make the task easy. Let's start how can we do that.


For this, we have to follow some procedure. 

  1. Make a ZIP file of old server files
  2. Upload Easy Server File Transfer Using PHP script in new server
  3. Copy old server zip link paste it into the source input
  4.  Type new filename into destination input and press transfer button
  5. Enjoy!


Also read: How To Generate The Same Sentence Unique Every Time Using PHP And Latin Character

How does it work?

It works with a very easy procedure.  The system copies the zip file from the old server to the new server. Just it. isn't it pretty?

Let's see the code of the script. 


<?php
@ini_set('max_execution_time',0);
$message = null;
if(isset($_POST['source'])&&isset($_POST['destination'])){	$transfer = true;	$source = $_POST['source'];	$destination = $_POST['destination']; $source_ext = pathinfo($source, PATHINFO_EXTENSION); $source_ext = pathinfo($source, PATHINFO_EXTENSION); $destination_ext = pathinfo($destination, PATHINFO_EXTENSION);	if (!filter_var($source, FILTER_VALIDATE_URL)) {	$transfer = false;	$message = '<div class="alert alert-danger text-center">Your source is not a valid URL</div>';	}	else	if ($source_ext!='zip') {	$transfer = false;	$message = '<div class="alert alert-danger text-center">Your source is not a ZIP File</div>';	}	else	if ($destination_ext!='zip') {	$transfer = false;	$message = '<div class="alert alert-danger text-center">Your destination filename is not a ZIP Format</div>';	}	if($transfer){	if(copy($source,$destination)){	$message = '<div class="alert alert-success text-center">Your requested file has been transfered.</div>';	}	}
}
?>
<head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Server File Transfer By phpans.com</title>	<link rel="shortcut icon" href="https://phpans.com/public/icon/favicon.ico" type="image/x-icon"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body> <div class="header text-center"> <img src="https://phpans.com/public/images/logo.png" alt="PHPAns" title="PHPAns"> </div> <div class="container content"> <h1 class="h3 bg-primary text-center" style="padding: 5px;">Easy Server File Transfer By phpans.com</h1>	<?php echo $message; ?> <div class="text-center">
<form method="post"> <div class="form-group"> <label for="source">ZIP File Link</label> <input type="text" name="source" class="form-control" placeholder="http://example.com/file.zip" required="required"> </div> <div class="form-group"> <label for="destination">Destination</label> <input type="text" name="destination" class="form-control" placeholder="newfile.zip or directory/newfile.zip" required="required"> </div> <button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-transfer"></i> Transfer</button>
</form> <br/> <h3><a target="_blank" href="https://phpans.com/easy-server-file-transfer-using-php/">Read <b>Easy Server File Transfer</b> Tutorial</a></h3></div> </div> <div class="footer text-center">&copy; 2015-<?php echo date('Y'); ?> <a target="_blank" href="https://phpans.com">phpans.com</a></div>
</body>
</html>


Just this code, If you want to copy your file into subdirectory then you have to input new file name with the directory name. For example, your script runs in the public_html directory and your new file name is application.zip and you want to copy old server file into app directory then you have to input destination as app/newfilename.zip and then the system will copy the file to the app directory.  After transfer file, you can delete this file from hosting. That's it.

You can download the file from GitHub

I hope you understand this system. Isn't it easy enough? I hope you understand easy file transfer using PHP. If you have any question you can comment below. If you love the system, please encourage us by sharing this. 

Sajjad Hossain
Hi, I'm Sajjad Hossain, a PHP Developer working on PHP Development since 2012. If you have a project that you want to start you can contact me. I'm currently available for freelance work. Ping me on Facebook, WhatsApp or Skype.

We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy
Top