Jump to content

zipping files


the_oliver

Recommended Posts

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.

Link to comment
Share on other sites

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;
						}
					}
				}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.