php 下载一个zip,php – 创建一个zip文件并下载

我正在尝试通过在本地服务器上创建zip文件来下载一个2文件.该文件是以zip格式下载的,但是当我尝试提取it.it给出错误:

未找到中央目录签名.这个文件不是

一个zip文件,或者它构成一个多部分存档的一个磁盘.在里面

后一种情况下会找到中央目录和zip文件的注释

该存档的最后一个磁盘.

我正在使用以下代码:

$file_names = array('iMUST Operating Manual V1.3a.pdf','iMUST Product Information Sheet.pdf');

//Archive name

$archive_file_name=$name.'iMUST_Products.zip';

//Download Files path

$file_path=$_SERVER['DOCUMENT_ROOT'].'/Harshal/files/';

zipFilesAndDownload($file_names,$archive_file_name,$file_path);

function zipFilesAndDownload($file_names,$archive_file_name,$file_path)

{

//echo $file_path;die;

$zip = new ZipArchive();

//create the file and throw the error if unsuccessful

if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {

exit("cannot open \n");

}

//add each files of $file_name array to archive

foreach($file_names as $files)

{

$zip->addFile($file_path.$files,$files);

//echo $file_path.$files,$files."

}

$zip->close();

//then send the headers to force download the zip file

header("Content-type: application/zip");

header("Content-Disposition: attachment; filename=$archive_file_name");

header("Pragma: no-cache");

header("Expires: 0");

readfile("$archive_file_name");

exit;

}

?>

我检查了所有传入函数的变量的值,一切都很好,请看这个.提前谢谢.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值