Logo
Unzip Zip File
Online Now: 2
Snippet Code
Need to unzip a file? this function can do that for you.

Introduction


It is reccomended that the functions.php file and the file that exicutes the 
unzip function are NOT in the same directory as the zip files.

unzip  ( string $zipfile , string $newLocation )

zipfile gets the name of the current zip file.
newLocation is where you want to store all the information that is in the zip file.

functions.php


<?php
    
function unzip($location,$newLocation){
        if(
exec("unzip $location",$arr)){
            
mkdir($newLocation);
            for(
$i 1;$icount($arr);$i++){
                
$file trim(preg_replace("~inflating: ~","",$arr[$i]));
                
copy($location.'/'.$file,$newLocation.'/'.$file);
                
unlink($location.'/'.$file);
            }
            return 
TRUE;
        }else{
            return 
FALSE;
        }
    }
?>

extractZip.php


<?php
include 'functions.php';
if(
unzip('zipedfiles/test.zip','unziped/myNewZip'))
    echo 
'Success!';
else
    echo 
'Error';
?>
 
Snippet Comments

Add Your Comment

types of doctors
2011-06-25 18:26:32
Simple and clean, thanks.
Boat Licence
2011-06-22 20:00:10
This works so good when it comes to unzipping files. I have used it in the past and it works so well. It is designed so good.
orlando cosmetic dentists
2011-06-21 19:09:25
The process on this is so good. There is so much that you can get from this.
family man
2011-03-01 23:50:41
Thanks that was a good bit of code.
penn george
2011-03-01 06:15:34
great! you just answered my homework today.
php scripts
2010-09-14 00:39:24
i need to say. i need this script. thank you buddy.
CasTex
2009-11-23 00:00:00
Simple and clean, thanks.
Anonymous
2009-10-06 00:00:00
Try uploading it to your server and try it there. This is php and will not work on your windows desktop.
Sam Yong
2009-07-25 00:00:00
This will not work on certain platforms such as Windows.

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Professional
Current Score: 3.06
Total votes: 171
Total Views: 6359

Other top snippets by admin:

1. JPEG to ASCII Converter
2. Add (th, st, nd, rd, th) to the end of a number
3. Dynamic Page Content From Links
4. AJAX Quickie
5. Simple Image CAPTCHA

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative