php 6 下载图片下载,下载图片.txt

thinkphp 批量打包下载图片到本地电脑

O-Striue-O 2018-08-10 16:13:33 1365 收藏

文章标签: php readfile 批量下载

版权

//批量下载图片

public function picDownload(){

if(IS_GET) {

// phpinfo();

// exit;

$type = I('get.type', 0, 'intval');

$bid = I('get.bid', 0, 'intval');

$images = M('images')->where(array('bid'=>$bid,'type'=>$type,'del'=>0))->select();

$filename = "./Uploads/" . date ( 'YmdH' ) . ".zip";

// 生成文件

$zip = new \ZipArchive ();

// 使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释

if ($zip->open ($filename ,\ZipArchive::OVERWRITE) !== true) {

//OVERWRITE 参数会覆写压缩包的文件 文件必须已经存在

if($zip->open ($filename ,\ZipArchive::CREATE) !== true){

// 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip

exit ( '无法打开文件,或者文件创建失败' );

}

}

foreach($images as $key => $v){

$v['swfimglist'] = substr($v['swfimglist'],1);

$zip->addEmptyDir("attach");

if(file_exists($v['swfimglist'])){

$zip->addFile($v['swfimglist'], basename($v['swfimglist']));

} else {

// die('图片地址不对哦');

echo 'error';

exit;

}

}

}

// 关闭

$zip->close ();

//下面是输出下载;

header ( "Cache-Control: max-age=0" );

header ( "Content-Description: File Transfer" );

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 );//输出文件;

exit;

}

本地环境要开启ZIP;linux需开启zlib,并且创建文件的目录权限要有写入权限

一键复制

编辑

Web IDE

原始数据

按行查看

历史

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值