zipArchive - corrupting files?
| From: | KMiller | Date: | Wed, 07 Mar 2007 01:50:41 +0000 |
| Subject: | zipArchive - corrupting files? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-249952@lists.php.net to get a copy of this message | ||
Been playing with this for a few hours and it seems that anything but a plain
text file (doc,xls,pdf,etc.) is being trashed by ZipArchive.
Has anyone had similar experiences or am I just doing something stupid and
can't see it?
Whatever the problem is, it certainly is silent about it. I thought it may
be a permissions thing but that doesn't seem to be it. The one file it
doesn't mess up is a plain text file. Anything else gets trashed.
-km
public function zipAction() {
$params = SiteControllers::getParams();
if(!isset($params['file'])) {
echo "zip: file param expected - not found";
return false;
}
$file = $params['file'];
if(!file_exists("uploads/{$file}")) {
echo "file to zip: {$file} not found";
return false;
}
$zip = new ZipArchive;
$res = $zip->open("uploads/{$file}.zip", ZipArchive::OVERWRITE);
if ($res === TRUE) {
$zip->addFile("uploads/{$file}","{$file}");
$zip->close();
unlink("uploads/{$file}");
echo "{$file} - was zipped";
return true;
} else {
echo "{$file} - zip failed";
return false;
}
}
public function unzipAction() {
$params = SiteControllers::getParams();
$file = $params['file'];
if(!isset($params['file'])) {
echo "unzip: file param expected - not found";
return false;
}
$zfn = "uploads/{$file}.zip";
if(!file_exists($zfn)) {
echo "zip file: {$zfn} not found";
return false;
}
if(file_exists("uploads/{$file}")) {
echo "file to unzip: {$file} exists";
return false;
}
$zip = new ZipArchive;
$res = $zip->open($zfn);
if ($res === TRUE) {
$zip->extractTo("uploads/");
$zip->close();
echo "{$file}: unzipped";
unlink($zfn);
return true;
} else {
echo "unzip for: {$file} failed";
return false;
}
}
--
View this message in context: http://www.nabble.com/zipArchive---corrupting-files--tf3359654.html#a9345356
Sent from the PHP - General mailing list archive at Nabble.com.