Jump to content
The Uniform Server Community
Sign in to follow this  
Blake Senftner

php's zip_archive class writes corrupt files in Coral 8.5.5

Recommended Posts

Hey all,


I have a utility function using the zip_archive class that makes directories into zip files. (I've put a copy at the bottom of this post.) Not sure when this broke, because when I wrote and testing the function under a previous version of Coral, it worked fine. Now, however, the zip files created do not uncompress into their contents, but uncompress into another zip file - endlessly, over and over again.


Maybe something else is broken, like the unzipping utility built into OSX. If you know of anything like that, please chime in!


Anyway, I'm perfectly fine continuing with Coral 8.5.5 unless there's some good reason to upgrade. I've got a product launch in about 4 weeks, and don't really have the time to troubleshoot things going wrong with an upgrade to Coral, unless something important like bug fixes to the zip_archive class are in the upgrade.


Thanks for any information you can offer!


* recursive zip directory add, just pass in the path to a directory as 'src' and
* it's recursive contents are added to the zip archive created at 'destination' */
function _cgrn_front_zipDirectory($source, $destination) {
if (!file_exists($source)) {
   _devReport( '_cgrn_front_zipDirectory: source "'.$source.'" does not exist!' );
   return false;

$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
   _devReport( '_cgrn_front_zipDirectory: failed to create zip at "'.$destination.'"!' );
   return false;

$source = str_replace('\\', '/', realpath($source));

if (is_dir($source) === true)
	$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

	foreach ($files as $file)
		$file = str_replace('\\', '/', realpath($file));

		if (is_dir($file) === true)
			$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
		else if (is_file($file) === true)
			$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
else if (is_file($source) === true)
	$zip->addFromString(basename($source), file_get_contents($source));

return $zip->close();

Share this post

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Sign in to follow this  

  • Create New...