簡體   English   中英

為什么我的.zip文件下載為空?

[英]Why my .zip file is downloaded empty?

我正在嘗試通過服務器開始下載zip文件。

此類zip文件包含許多生成的pdf。

問題是袋子丟了,但是把它標記為打開,這是損壞的,或者有錯誤,當我提取時告訴我是空的。

我在這里完成整個過程嗎?

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

移動$zip->close(); readfile($filename)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM