Tag

Archive

Browsing

Today, We are going to learn programmatically PHP create ZIP file. PHP provides ZipArchive class using that we can easily create the zip file. But Today, I am going to share function with you using that function you can easily create the ZIP file by passing the directory name or file name.

Suddenly, My client tells me to move his project from one server to another server and his use the shared hosting. So, I have only FTP detail at that time I created “createZip” function for creating the zip file of files or directories. I am going to share that function with you So, you can easily create the zip file without hard work using PHP. You just need to write single line code for PHP creating ZIP file.

PHP create ZIP file

Just past the “createZip” function anywhere on your project then you just need to call that function for creating the zip file like

If you need to create the zip file of the current directory then you need to pass dot except for the directory path like

Or else you should pass the full directory path like

After, Creating the ZIP file if you want to move it another server without download it on your local system then You can follow my tutorial “Download Archive file from URL

If you face any issue after using this code please write the comment below.

Today, We are going to learn how to Download zip file from URL using PHP. PHP download archive file using single line of code. We can easily download the any file using PHP single line of code. We use file_put_contents for download file.

PHP Download Archive file

You can download any types of file using this function like JPG, JPEG, EXE, PNG, MP4, MP3 etc…

This trick is very useful when you want to move project to new server. We don’t need to download project to local system and then upload it to new server. Just create zip file of the project and create PHP script to new server then directly download project file on new server using PHP script.

If you face any problem after using this code please write a comment.