the_oliver Posted July 28, 2007 Share Posted July 28, 2007 Hello, Im wondering if there is a way, through a php script, to create a zip file of the contents of a folder? E.g. the web user would submit a form, and after a bit of validation, a zip file would be created, and a download forced. How could would i go about creating the zip file through php? (Im hosted on a Windows mashine) Thanks for your thoughts. Quote Link to comment Share on other sites More sharing options...
Smackie Posted July 29, 2007 Share Posted July 29, 2007 http://www.zend.com/zend/spotlight/creating-zip-files2.php go there it talks about Zipping in php... just remember use http://www.google.com its your best friend Quote Link to comment Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 I had a lot of trouble with zipping stuff at first when I was trying to figure it out the other day, but once you figure out which functions to use, it's actually quite easy.... The following is something I used in a script the other day: //$out was preset.... if(class_exists('ZipArchive')) { $zname = microtime(); $zname = explode(" ", $zname); $zname = (int) $zname[1]; $zname = $zname / (rand(1,10)); $zip = new ZipArchive(); if ($zip->open('includes/CTools/temp/zips/'.$zname, ZIPARCHIVE::CREATE)===TRUE) { $zip->addFromString("output.txt" . time(), $out); $zip->close(); $gc = @file_get_contents('includes/CTools/temp/zips/'.$zname); if($gc) { ForceDownloadHeaders($filename . '.zip', strlen($gc)); echo $gc; unset($gc); $zipped = true; exit; } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.