How to unzip a file using PHP

How to unzip a file using PHP


Description

 

Yesterday, I discovered a simple PHP script that makes installing WPMU, BuddyPress, WordPress, or really anything else a quick and painless process.

(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL zip >= 1.1.0) 

ZipArchive::extractTo — Extract the contents of the archive.

 

What do you need is a zipped folder!

 

✓Here is the script: 

bool ZipArchive::extractTo( string $destination, mixed $entries ) or Download the PHP file (but make sure to change the file extension from the txt to php.

 

I have been installing WordPress MU and BuddyPress a lot recently as I test and test and test it for a client’s website. 

 

The uploading of files via ftp has been the biggest consumer of time during this process. 

 

How to Unzip Folders on the Server Using a Simple PHP Script Simply 

 

  1. Upload your zipped file to the server (in my case, “wpmu.zip”).

  2. Edit unzip.php to point to your file (download unzip.php above).

  3. Upload unzip.php to the same folder as your zipped file. 

  4. Open a browser and point it to http://mydomain.com/unzip.php (make sure to change “mydomain.com” to your domain).

 

Parameter list

pathto

Where to extract the files.

files

The entries to extract.

It can be either the name of an entry or an array of names Return Values This function returns trueon success or falseif an error occurs.

 

Warnings

 

Default permissions for checked out files and folders give the widest possible access. 

 

This can be restricted by setting the current umask, which can be changed using umask() .

 

How To do to unzip a file with PHP

 

So we can use the ZipArchive class.

 

ZipArchive is a simple utility class for zipping and unzipping files. 

 

We don’t require any extra additional plugins for working with zip files. 

 

ZipArchive class provides us a facility to create a zip file or to extract the existing zip file. 

 

The ZipArchive class has a method called extractTo to extract the contents of the complete archive or the given files to the specified destination. 

 

The ZipArchive class also has a lot of other methods and properties to help you get more information about the archive before extracting all its contents.

 

Note

 

With the file element, you can select the zip file that you want to extract. 

 

If a selected file is valid then pass to open() method and extract it to the specified path using extractTo() method.


Download Unzipper Pro

Next Post Previous Post
No Comment
Add Comment
comment url