php: extracting large files from zip archives

Posted on 2007-08-07
Last Modified: 2013-11-05
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 = '';
  $archive = new PclZip('');
  if ($archive->extract(PCLZIP_OPT_PATH, 'raw_data') == 0) {
    die("Error : ".$archive->errorInfo(true));


I tried another class - It only creates a zero-length file.

I also tried direct unix unzip execution as


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?


Question by:andy7789
    LVL 48

    Accepted Solution

    If you are using exec('unzip ...') the php-script will first continue if unzip has finished. To get the returncode of unzip see 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

    Author Comment

    so, i will keep the exec() solution and stop looking for some other classes - thank you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now