#1
  1. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2006
    Location
    I'm sneaking up behind you.
    Posts
    1,490
    Rep Power
    832

    Create zip files - archive only, do not compress


    Hello,

    I have to send a collection of some files (number can range from 20-100) to users. PHP has the zip file functions for the purpose; well and good.

    Problem is, most of those files will be jpeg's (which is a compressed format). As i see it, it doesn't make sense in compressing a compressed file which results in no-compression or negligible-compression; it is a waste of time and resources.

    So, is there any way to disable the compression part? Just create the archive by grouping all the files but do not compress.

    Thank you.
    Why do we always seek someone, something or some thought? Are we afraid of ourselves?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    82
    Rep Power
    43
    explore apache settings

    Code:
    <IfModule mod_deflate.c>
        SetOutputFilter DEFLATE
        # file-types indicated will not be compressed
        SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
        <IfModule mod_headers.c>
            Header append Vary User-Agent
        </IfModule>
    </IfModule>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2006
    Location
    I'm sneaking up behind you.
    Posts
    1,490
    Rep Power
    832
    Originally Posted by PradeepKr
    explore apache settings

    Code:
    <IfModule mod_deflate.c>
        SetOutputFilter DEFLATE
        # file-types indicated will not be compressed
        SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
        <IfModule mod_headers.c>
            Header append Vary User-Agent
        </IfModule>
    </IfModule>
    That, i assume will be helpful when i am delivering the zip files. I want to disable compression while "creating" the files using the ZipArchive() class of php.
    Why do we always seek someone, something or some thought? Are we afraid of ourselves?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2006
    Location
    I'm sneaking up behind you.
    Posts
    1,490
    Rep Power
    832
    There is a constant, ZIPARCHIVE::CM_STORE. It is read only as of now; useful for determining the compression method of an existing zip file. It is not possible to use it while creating a zip file.

    Here is the source link, http://bugs.php.net/bug.php?id=41243
    Why do we always seek someone, something or some thought? Are we afraid of ourselves?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    I use B1 archiver for that. Just when choosing compression mode I opt for "Store" mode. In that case files do not get actually compressed but only stored together.
  10. #6
  11. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,944
    Rep Power
    4033
    Use an external CLI tool to generate the zip file, such 7zip or zip. You can build up a command line and then use exec() to run it.

    Code:
    //generate an array of files to compress, $files
    $files = array_map('escapeshellarg', $files);
    $output = tempnam(); //get temporary file name
    $cmd = 'zip -0 '.escapeshellarg($output).' '.implode(' ', $files);
    exec($cmd, $output, $ret);
    if ($ret==0){
       //success
       //do whatever you need with $output
       unlink($output); //cleanup
    
    }
    else {
      //fail
       unlink($output); //cleanup
    }
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Has anyone noticed this thread is 2 1/2 years old?

    Comments on this post

    • ptr2void agrees : I suspect another SEO. "She" has gone around either posting in SEO discussions or bumping old topics.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo