Everyone can easily unzip on a Windows or Linux provided OS access must be given. But how to unzip a file with PHP? This is very useful when you are uploading a heavy folder containing say more than 100 or may be 1000 files. Or if you are uploading a complete website to a new host.

If you upload the folder through FTP, FTP upload each files individually and run individual commands for each files and does not upload the complete folder in one go which takes a lot of time.

Say if you upload a folder of size 10 mb containing 400 files on a broadband 1Mbps connection, it will take you at least 20 mins to finish the upload. However, you will be amazed if you do it my way by zipping all the files, uploading it and unzipping them online, the process will take less than a minute.

The logic is simple to understand. When you zip the 400 files, the no. of file to upload now becomes one. So FTP can upload your file with just single command and the folder size is compressed to at least 50% of the original size. Make a file unzip.php. Let me explain the coding for this file:

You are ready to go. Just upload the unzip.php file to your directory where you have uploaded the zip folder. For example, your domain name is www.x-developer.com and the file you have uploaded is demp.zip. Your url to unzip the file will be:

http://www.x-developer.com/unzip.php?f=demo.zip

Please note:
This script requires php safe mode to be turned off. It will not work if the safe mode is turned on. If you do not know how to turn off the safe mode, let me explain:

open the php.ini file in the root. If you don’t find it, create a new file php.ini and add the following code:

safe_mode = off

Happy to help, if you have any questions.

Be Sociable, Share!