PHP实现打包下载文件的方法示例
发布时间:2021-03-04 22:29:11 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解PHP实现打包下载文件的方法。分享给大家供大家参考,具体如下: $value) { $fileContent = ''; $fileContent = $this->CurlDownload($value['url']); if( $fileContent ) { $__tmp = $this->SaveFile( $value['url'],$path,$fileContent ); $i
本篇章节讲解PHP实现打包下载文件的方法。分享给大家供大家参考,具体如下: $value) {
$fileContent = '';
$fileContent = $this->CurlDownload($value['url']);
if( $fileContent )
{
$__tmp = $this->SaveFile( $value['url'],$path,$fileContent );
$items[] = $__tmp[0];
$names[] = $value['name'].'_'.($key+1).'.'.$__tmp[1];
}
}
if( $items )
{
$zip = new ZipArchive();
$filename = time().'download.zip';
$zipname = $path.'/'.$filename;
if (!file_exists($zipname)) {
$res = $zip->open($zipname,ZipArchive::CREATE | ZipArchive::OVERWRITE);
if ($res) {
foreach ($items as $k => $v) {
$value = explode("/",$v);
$end = end($value);
$zip->addFile($v,$end);
$zip->renameName($end,$names[$k]);
}
$zip->close();
} else {
return '';
}
//通过前端js跳转zip地址下载,让不使用php代码下载zip文件
//if (file_exists($zipname)) {
//拼接附件地址
//$redirect = 域名.$path_redirect.'/'.$filename;
//return $redirect;
//header("Location:".$redirect);
/ (编辑:开发网_开封站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |