2016-08-24 11 views
0

私は自分のサーバーからzipのダウンロードを開始しようとしています。私の.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(); 
} 
+0

基本的なデバッグ: 'readfile($ files);'あなたのディレクトリタイターオブジェクトを渡すと、readfile()は何をすると思いますか? –

+0

私の.zipファイルをPCのユーザにダウンロードしたい – David

+0

なぜファイル名が必要な関数にオブジェクトを与えるのですか? –

答えて

0

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

関連する問題