Archivo zip bajado con tamaño 0 o vacio./volume1/web/familia/fotos/album/rodriguezobject(ZipArchive)
Publicado por jose (71 intervenciones) el 12/03/2021 15:32:39
Buenas tardes,
Tengo una función de php para crear un archivo zip y bajarlo a través del navegador.
El resultado que me da var_dump($zip) es: code]/volume1/web/familia/fotos/album/rodriguezobject(ZipArchive)#1 (5) { ["status"]=> int(0) ["statusSys"]=> int(0) ["numFiles"]=> int(192) ["filename"]=> string(40) "/volume1/web/familia/fotos/zip/Fotos.zip" ["comment"]=> string(0) "" }[/code]
Y el archivo lo guarda correctemante, ocupa el tamaño y contiene los archivos correctos.
Sin embargo baja con 0 bytes.
He realizado varios cambios con los headers y no encuentro la forma, podría alguién decirme donde está el problema.
Muchas gracias,
Tengo una función de php para crear un archivo zip y bajarlo a través del navegador.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function comprimir($dir) {
// Get real path for our folder
$rootPath = realpath($dir);
// Initialize archive object
$zip = new ZipArchive();
$filename = "../../fotos/zip/Fotos.zip";
$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
var_dump($zip);
// Zip archive will be created only after closing object
$zip->close();
$fileName = basename($filename);
//$filePath = 'files/'.$fileName;
if(!empty($filename) && file_exists($filename)){
// Define headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$fileName");
header('Content-Length: ' . filesize($fileName));
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
// Read the file
readfile($filename);
exit;
}else{
echo 'The file does not exist.';
}
//Limpiando archivo
//unlink($filename);
}
El resultado que me da var_dump($zip) es: code]/volume1/web/familia/fotos/album/rodriguezobject(ZipArchive)#1 (5) { ["status"]=> int(0) ["statusSys"]=> int(0) ["numFiles"]=> int(192) ["filename"]=> string(40) "/volume1/web/familia/fotos/zip/Fotos.zip" ["comment"]=> string(0) "" }[/code]
Y el archivo lo guarda correctemante, ocupa el tamaño y contiene los archivos correctos.
Sin embargo baja con 0 bytes.
He realizado varios cambios con los headers y no encuentro la forma, podría alguién decirme donde está el problema.
Muchas gracias,
Valora esta pregunta


0