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 http://example.com/archieves/test.zip.
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.
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.
<?php $arr_file = explode("/", $_POST['source']); $filename = end($arr_file); file_put_contents($filename, file_get_contents($_POST['source'])); echo 'success'; ?>
If you liked this article, then please subscribe to our YouTube Channel for video tutorials.