note 69407 deleted from ref.zip by danbrown
| From: | danbrown@php.net | Date: | Sun, 25 Oct 2009 13:11:08 +0000 |
| Subject: | note 69407 deleted from ref.zip by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162058@lists.php.net to get a copy of this message | ||
Note Submitter: phpContrib [ a t ] eSurfers D o t COM
----
1) A warning to all users of PHP Zipping/Unzipping Classes: most of them require the whole content
of the ZIP file and/or the unzipped contents to stay in memory. They work very well, but might fail
with very large files. Keep this in mind before starting development of a project involving large
ZIP files.
2) If all you need is to unzip files to a folder, and your server has a zip command line tool, all
you might need is a function like this:
if(!defined('UNZIP_CMD')) define('UNZIP_CMD','unzip -o @_SRC_@ -x -d
@_DST_@');
function UnzipAllFiles($zipFile,$zipDir) {
$unzipCmd=UNZIP_CMD;
$unzipCmd=str_replace('@_SRC_@',$zipFile,$unzipCmd);
$unzipCmd=str_replace('@_DST_@',$zipDir,$unzipCmd);
$res=-1; // any nonzero value
$UnusedArrayResult=array();
$UnusedStringResult=exec($unzipCmd,$UnusedArrayResult,$res);
return ($res==0);
}
// * * * You DO NOT NEED the ZIP lib or M-ZIP to use this, but you will need the tool M-ZIP uses
(unzip.exe or unzip for linux). * * *
// Use it this way:
$zipFile='/path/to/uploaded_file.zip';
$whereToUnzip='/path/to/writable/folder/';
$result=UnzipAllFiles($zipFile,$whereToUnzip);
if($result===FALSE) echo('FAILED');
else echo('SUCCESS');
By changing UNZIP_CMD (the same constant as in the m-zip lib) you can
of course untar, unarc, unrar, etc... provided you have the correct
unwhatever command or unwhatever.exe executable and write its correct syntax in UNZIP_CMD.
To see details of what tools you need and where to put them (or to use a syntax compatible to the
standard zip lib) see http://eSurfers.com/m-zip/