php文件打包下载
1. 怎样用多文件php实现多文件下载
好可怜啊,谁给你的任务,这个是不可能的,和框架、语言都没关系,是不是你的上级看错了文档啊,人家要求多个文件用zip打包下载(比如把文档中的“别忘了用zip”看成“别用zip”)
这种只能js同时弹出多窗口了,例如
<formclass="download_form"target="download_url_1"action="download_url_1"></form>
<formclass="download_form"target="download_url_2"action="download_url_2"></form>
...
<buttononclick="$('form.download_form').each(function(){this.submit();})"type="button">点</button>
只要下载是正常的,这种弹出会在用户操作后(下载或取消)自动消失的。但是用户要一个一个点还是很差劲的用户体验。
window.open也行,但是容易受浏览器弹窗设置影响,所以不建议。
2. PHP网页上打包文件生成压缩文件zip,并弹出下载
既然你只是想学习如何打包.
那我重点就回答你这一块,正好我刚刚用到;
$filename="./".date('YmdH').".zip";//最终生成的文件名(含路径)
//生成文件
$zip=newZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit('无法打开文件,或者文件创建失败');
}
//$fileNameArr就是一个存储文件路径的数组比如array('/a/1.jpg,/a/2.jpg....');
foreach($fileNameArras$val){
$zip->addFile($val,basename($val));//第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下
}
$zip->close();//关闭
//下面是输出下载;
header("Cache-Control:max-age=0");
header("Content-Description:FileTransfer");
header('Content-disposition:attachment;filename='.basename($filename));//文件名
header("Content-Type:application/zip");//zip格式的
header("Content-Transfer-Encoding:binary");//告诉浏览器,这是二进制文件
header('Content-Length:'.filesize($filename));//告诉浏览器,文件大小
@readfile($filename);//输出文件;
3. php打包下载文件源码
打包,顾名思义,就是打包啊
用zip模块将选择的文件打包成一个文件,然后提供下载!
源码就不提供了,自己学习写吧
4. thinkphp打包exe
thinkphp 打包文件,并下载
/**
* 打包下载
* 注意文件路径都是相对路径
* 不能使用ajax的方式
* @return [type] [description]
*/
public function allzip(){
$param = $this->request->param();
$ids = explode(",",$param['id']);
//要打包的文件
foreach ($ids as $k => $v){
$files[] =substr(db('seofile')->where('id',$v)->value('fileurl'),1);
}
$zip = new \ZipArchive;
//压缩文件名
$filename = 'upload/file/download.zip';
//新建zip压缩包
$zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);
//循环压缩文件
foreach($files as $key => $value){
$zip->addFile($value,basename($value));
}
//打包zip
$zip->close();
header("Cache-Control:public");
header("Content-Description: File Transfer");
header("Content-disposition: attachment; filename=".basename($filename));//文件名
//header("Content-Type: application/force-download");
header("Content-Type:application/zip"); //格式为zip
header("Content-Transfer-Encoding:binary"); //这是二进制文件
header("Content-Length:".filesize($filename)); //文件大小
@readfile($filename);
// @unlink($filename);
}
5. php如何实现文件夹的打包下载详细操作步骤
publicfunctiondownloads(){
$file="./Ludian_Disaster_Relief_Map_Operation_Guide.pdf";
if(file_exists($file)){
header('Content-Description:FileTransfer');
header('Content-Type:application/octet-stream');
header('Content-Disposition:attachment;filename='.basename($file));
header('Content-Transfer-Encoding:binary');
header('Expires:历念差0');
header('高尺Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('肢皮Pragma:public');
header('Content-Length:'.filesize($file));
ob_clean();
flush();
readfile($file);
}else{
$this->error("文件不存在");
}
}
6. php 如何把文件夹及文件夹下面的所有文件打包成压缩包,在页面上用户点击下载按钮即可下载到本地
一般不会下载的时候重新打包,因为php打包是一个凳改拿非常消耗资源的过程枣搭。
使用php zip 打包,然后记录包的路径,下载的时候直接下歼乎载该路径文件即可。
7. 求大神帮把php文件给我打包成zip的、谢啦
1,芹滚贺程序操作:PHP的zip文备者件长传到附件了,放在网站的根目录就行了。
2,不同操嫌派作:选择PHP文件鼠标右键进行软件打包。