Jump to content


Photo

php's zip_archive class writes corrupt files in Coral 8.5.5


  • Please log in to reply
No replies to this topic

#1 Blake Senftner

Blake Senftner

    Newbie

  • Support Team
  • Pip
  • 4 posts
  • Main OS: Windows Vista

Posted 26 September 2012 - 05:31 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users