Zapisuję foldery i pliki za pomocą php, ale kiedy próbuję otworzyć plik zip, otrzymuję zamiast tego plik cpgz. Po wyodrębnieniu tego pliku otrzymuję kolejny plik zip. To, co robi, to basically skanuje bieżący folder, aby pliki i foldery były zipowane. Jest to kod używam:Spakowany plik z PHP powoduje, że plik cpgz po ekstrakcji
function Zip($source, $destination)
{
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
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();
}
if($_GET["archive"]== 'true'){
$date = date("Ymd_Hi");
$dir = dirname(__FILE__);
$filename = $date.".zip";
Zip(getcwd(), $filename);
header("Content-disposition: attachment; filename=$filename");
header('Content-type: application/zip');
readfile($filename);
unlink($filename);
}
- @ Steven, to twój plik zip na tym samym serwerze, co kod aplikacji? Miałem dokładnie ten sam problem, który rozwiązałem tutaj (http://stackoverflow.com/questions/11495103/opening-downloaded-zip-file-creates-cpgz-file). A jak wyglądasz "header()"? –