filesize():stat.zip

时间:2016-01-08 16:10:34

标签: php zip

我正在创建一个包含2个文件但在打开时显示错误的zip文件。但是当我用代码编辑器打开它时会显示一些错误。

我的主要代码是:

<?php
    $files = array(
                'localhost/apache_pb2_ani.gif',
                'localhost/apache_pb2.png');
                $zipname = 'file.zip';
                $zip = new ZipArchive;
                $zip->open($zipname, ZipArchive::CREATE);
                foreach ($files as $file) {
                  $zip->addFile($file);
                }
                $zip->close();
            //if true, good; if false, zip creation failed
            header('Content-Type: application/zip');
            header('Content-disposition: attachment; filename='.$zipname);
            header('Content-Length: ' . filesize($zipname));
            readfile($zipname);
    ?>

错误是:

Warning:filesize(): stat failed for file.zip in C:\xampp\htdocs\download.php on line 19

Warning: readfile(file.zip): failed to open stream: No such file or directory in <b>C:\xampp\htdocs\download.php on line 20

什么似乎是错误?

1 个答案:

答案 0 :(得分:0)

如果我在$files数组中使用的文件路径不正确,我可以重现警告。

您确定图像的路径(带有“localhost /”)是否正确?

$files = array(
    'localhost/apache_pb2_ani.gif',
    'localhost/apache_pb2.png'
);