Move Zip File From Server To Server Using Ajax

This is a quick post on the topic of moving zip files from server to server using Ajax. Recently, I have worked on a similar task for one of my client’s websites. It may be helpful for someone so I decided to write a post on it.

For this article, I am assuming you have a submit button and you need to fetch a zip file from another server. Let’s say the server path for a zip file is

Place the below code in your file. In this file, we are giving an Ajax call on the clicking of a button. To the Ajax file, we send a source path of a zip file.

<input type="button" class="submit" value="Submit">
<script src=""></script>
<script type="text/javascript">
    $(function() {
        $('body').on('click', '.submit', function() {
                type: 'POST',
                url: 'ajax.php',
                data: {'source' : ''},
                success:function(response) {

Next, in the ajax.php file, we write actual code to move the zip file from server to server. Below is the code in the ajax.php file.

$arr_file = explode("/", $_POST['source']);
$filename = end($arr_file);
file_put_contents($filename, file_get_contents($_POST['source']));
echo 'success';

That’s It. I hope you understand how to move a zip file from server to server using Ajax. If you have any questions or suggestions please leave a comment below. Please read our related articles Ajax File Upload With PHP And jQuery and Drag And Drop File Upload Using JavaScript And PHP.

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *