Web Analytics Made Easy -
StatCounter How to uncompress a zip file on the fly - CodingForum


No announcement yet.

How to uncompress a zip file on the fly

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to uncompress a zip file on the fly

    I've got the following PHP code...
    PHP Code:
    //<!-- No index start 1 -->
    $_GET['id'])) {
    //id is set, include file
    $id $_GET['id'];
    $sql "SELECT fileType, fileName from fileTbl where metricID=".$id;
    $rs getDBData($sql);
    $r mssql_fetch_assoc($rs);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-type: ".$r['fileType']);
    //name the download file $r['fileName']
    $user_agent strtolower ($_SERVER["HTTP_USER_AGENT"]);
        if ((
    is_integer (strpos($user_agent"msie"))) && (is_integer (strpos($user_agent"win")))) {
    header"Content-Disposition: filename=".$r['fileName'].";" );
        } else {
    header"Content-Disposition: attachment; filename=".$r['fileName'].";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize("//domain/path/to/metrics/".$r['fileName']));
    // The PDF source is in original.pdf

    else {
    //no id set, display error
    Which will return a file for downloading from a web site. The reason I have this code is because it's part of a secured area of the site. This is only included if the user has the correct credentials. I also have another secure area where admins can remotely upload the files to the web server. Butneither of these have anything to do with my problem, so I digress.

    My problem is, sometime people upload .zip files (compressed with winZip) and they are usually excel files which are zipped. Now when the user downloads this file, it prompts them to save the zip file to their c:\ drive and then they need to "unzip" the file. The problem I have is that a lot of users don't know how to do that. (Don't laugh, I've tried online documentation and help but to no avail) So I get a lot (ok, not a lot but a few a week) emails asking me to unzip the file and email it to them.

    Now, What I'd like to do is to have php automatically unzip the file before sending it back to the browser. Is that possible???
    Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
    Zend Certified Engineer

  • #2
    well you can using the zip extension (if enabled) or , on the server using exec() as zip is available on most servers , there is even a pure PHP zip decompression utility out there somewhere (just do some googleing)

    but methinks that easier would be to get your admins to zip as an executable zip file which auto-deflates ... assuming of course you trust your admins!!
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)