PHP – Unzip an uploaded file using php


If you dont have shell access to your server and need to unzip a file on your php server you can use the script below:

 <?php
     $zip = new ZipArchive;
     $res = $zip->open(’my_zip_file.zip’);
     if ($res === TRUE) {
         $zip->extractTo(’my_extract_to_dir/’);
         $zip->close();
         echo ‘ok’;
     } else {
         echo ‘failed’;
     }
?>

Basically it extracts the zip file into the directory you specify… make sure the directory you want to extract it to has write permissions. More info on this script is available on the php website One issue I ran into with this script was that I could not modify the files via my ftp program as they did not have permission set for this.

source:

http://bjw.co.nz/developer/php/62-php-unzip-an-uploaded-file-using-php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s