Jump to content

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
https://forums.phpfreaks.com/topic/222960-zip/
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
https://forums.phpfreaks.com/topic/222960-zip/#findComment-1152837
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.