[英]Why my .zip file is downloaded empty?
I'm trying to start a download of a zip through my server. 我正在尝试通过服务器开始下载zip文件。
This type of zip file contains a number of pdf that are generated. 此类zip文件包含许多生成的pdf。
The problem is that the bags and dump it but mark me open this damaged or there is an error and when I extract tells me is empty. 问题是袋子丢了,但是把它标记为打开,这是损坏的,或者有错误,当我提取时告诉我是空的。
Here I do the whole procedure? 我在这里完成整个过程吗?
Code of descargar.php descargar.php的代码
<?php
$zip = new ZipArchive();
$filename = 'walkingdead.zip';
if($zip->open($filename,ZIPARCHIVE::CREATE)===true) {
// Get real path for our folder
$rootPath = realpath('../walkingdead');
$zip->open('walking.zip', 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);
}
}
//Sin notificaciones, y que el server no comprima
@ini_set('error_reporting', E_ALL & ~ E_NOTICE);
@ini_set('zlib.output_compression', 'Off');
//Encabezados para archivos .zip
header('Content-Type: application/zip');
header('Content-Transfer-Encoding: Binary');
//El nombre predeterminado que verá el cliente
header('Content-disposition: attachment; filename="' . basename($filename) . '"');
//Que no haya límite en la ejecución del script
@set_time_limit(0);
//Imprime el contenido del archivo
readfile($filename);
// Zip archive will be created only after closing object
$zip->close();
}
Move $zip->close();
移动$zip->close();
to before readfile($filename)
. 到readfile($filename)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.