【问题标题】:filesize(): stat failed for file.zipfilesize():file.zip 的统计信息失败
【发布时间】:2016-01-09 00:44:21
【问题描述】:

我正在创建一个包含 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 &lt;b&gt;C:\xampp\htdocs\download.php on line 20

似乎是什么错误?

【问题讨论】:

  • 从数组中移除 localhost/。例如: apa​​che_pb2_ani.gif 只需要带有扩展名的文件名,还要确保将文件保存在此代码所在的同一位置。

标签: php zip


【解决方案1】:

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

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

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

【讨论】:

  • 是的,当我将它们输入地址栏时,它们会显示正确的图像
  • 在没有 'localhost/' 的情况下测试代码会发生什么?图片在哪个目录?
猜你喜欢
  • 1970-01-01
  • 2019-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-15
相关资源
最近更新 更多