Jump to content

ZIP


Recommended Posts

Hi guys,

I have some code for xtracting the contets of a zip file to a folder. Now this is the code:

	function extractupdate($file){
	$zip = zip_opne("$file");
	if(is_resource($zip)){
		while ($zip_entry = zip_read($zip)){
			$fp = fopen("zip/".zip_entry_name($zip_entry), "w");
			if(zip_entry_open($zip, $zip_entry, "r")){
				$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
				fwrite($fp,"$buf");
				zip_entry_close($zip_entry);
				fclose($fp);
			}
		}
		zip_close($zip);
	}
}

 

My question is how do I install the ZIP library into PHP. At the moment I am using PHP on Windows and using Apache, so I need a good way to add the ZIP library where I edit the php.ini etc..

 

Your help is much appreciated, thanks.

Link to comment
Share on other sites

Thanks thorpe, I have now done that.

So this is the "topology" of the code/files:

 

root/index.php

	$dir = opendir ("temp");
	while (false !== ($file = readdir($dir))) {
		if (strpos($file, '.zip',1)) {
			extractupdate($file);
            }

        }


function extractupdate($file){
	$zip = zip_open("$file");
	if ($zip){
		while ($zip_entry = zip_read($zip)){
			$update = rtrim($file, ".zip");
			$fp = fopen("zip/".zip_entry_name($zip_entry), "w");
			if(zip_entry_open($zip, $zip_entry, "r")){
				$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
				fwrite($fp,"$buf");
				zip_entry_close($zip_entry);
				fclose($fp);
			}
		}
		zip_close($zip);
	}
}

 

in root/temp/ there is a file 001.zip

 

the code is failing to extract to root/temp/zip/

 

Any help is much appreciated, thanks.

 

PS My aim is to extract the contents of the zip archive to the folder root/temp/zip/

Cheers

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.