我正在创建一个包含两个文件的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
看起来有什么错误?
如果我在$files
数组中使用的文件的路径不正确,我可以重新生成警告。
您确定到映像的路径(带有"localhost/")是正确的吗?
$files = array(
'localhost/apache_pb2_ani.gif',
'localhost/apache_pb2.png'
);