ZipArchive PHP returning emty zip file

时间:2018-02-03 10:52:46

标签: php

please help me, i tried to create zip file using ZipArchive in PHP but allways get Emty Zip file,

this is my code

> $files = array('/upload/download1.jpg','/upload/download2.jpg');
$dir=dirname($_SERVER["SCRIPT_FILENAME"]);
$zipname = 'testme123.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {

    $filename=$dir.$file;

    if(is_readable($filename))
    {
    $zip->addFile('C:\inetpub\wwwroot\wss\VirtualDirectories\80\downloadzip/upload/download1.jpg');

    }else{echo($filename . 'error');}
}
$zip->close();


header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);

?>

i try everything i know with addFile :

  • $file
  • dirname($_SERVER["SCRIPT_FILENAME"]) . $file
  • even hard coded the file path : C:\inetpub\wwwroot\wss\VirtualDirectories\80\downloadzip/upload/download1.jpg
  • C:\inetpub\wwwroot\wss\VirtualDirectories\80\downloadzip\upload\download1.jpg

but still not working i really don't know what i miss with this code

bytheway my php version 5.3.28 running on IIS win server 2008

1 个答案:

答案 0 :(得分:0)

我不知道它是如何发生的,但是,重新启动服务器后所有错误都消失了...... LOL