[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1509
  • Last Modified:

php: extracting large files from zip archives

Hi X-perts,

I need to extract a large file (about 100mb a single file) from a zip archive. I have been trying PclZip class and it works fine on relatively small files - even for huge archives of 500mb. However it does not work for a single large file (no warnings, no messages whatsoever). Here is my current code with PclZip

  $local_file = 'current_data_full.zip';
  $archive = new PclZip('current_data_full.zip');
  if ($archive->extract(PCLZIP_OPT_PATH, 'raw_data') == 0) {
    die("Error : ".$archive->errorInfo(true));


I tried another class - http://www.lost-in-code.com/2007/05/15/php-upload-extract-zip-archive/. It only creates a zero-length file.

I also tried direct unix unzip execution as

exec('unzip cur.zip');

This is the only code working for large files so far.

Please, advise some other zip classes working for huge files. I am using php 4.4.2

Another question, if I use exec('unzip ...'), it takes 5-10 sec to execute. How can I make sure that the file is fully extracted before continuing the script?


1 Solution
If you are using exec('unzip ...') the php-script will first continue if unzip has finished. To get the returncode of unzip see http://www.php.net/exec. AFAIK there are no classes for php 4.x which can cope good with larg files. php 5.x has a native interface/streamwrapper for zip-files which does not require a lot of memory when working with files inside the zip. Upgrade to php5.2.x
andy7789Author Commented:
so, i will keep the exec() solution and stop looking for some other classes - thank you

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now