本篇文章给大家带来的内容是关于Thinkphp批量下载图片和文件件的代码实例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
//批量下载图片
public function download_img_all(){
$dfile = tempnam('./public/upload/qr_code/', 'tmp');//产生一个临时文件,用于缓存下载文件
$zip = new Zipfile();
$filename = 'erweima'.'.zip'; //下载的默认文件名
// $image = M('Device')->field('erweima')->select();
// foreach($image as $v){
// $image_path = './public/upload/qr_code/';方法一
// $zip->add_path($image_path);
// // $zip->add_file(file_get_contents($v['erweima']), $v['erweima']);
// // 添加打包的图片,第一个参数是图片内容,第二个参数是压缩包里面的显示的名称, 可包含路径
// // 或是想打包整个目录 用
// }
$image_path = './public/upload/qr_code/';//方法二
$zip->add_path($image_path);
$zip->output($dfile); // 下载文件
ob_clean();
header('Pragma: public');
header('Last-Modified:'.gmdate('D, d M Y H:i:s') . 'GMT');
header('Cache-Control:no-store, no-cache, must-revalidate');
header('Cache-Control:pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding:binary');
header('Content-Encoding:none');
header('Content-type:multipart/form-data');
header('Content-Disposition:attachment; filename="'.$filename.'"'); //设置下载的默认文件名
header('Content-length:'. filesize($dfile));
$fp = fopen($dfile, 'r');
while(connection_status() == 0 && $buf = @fread($fp, 8192)){
echo $buf;
}
fclose($fp);
@unlink($dfile);
@flush();
@ob_flush();
exit();
}相关文章推荐:
v1.8新增功能简介: 一、后台新增生成网站地图和生成Sitemap.xml的功能。 二、新增下载中心功能,可在后台上传doc,xls,ppt,rar,pdf文件。 三、新增产品缩略图自动缩放功能,图片按比例缩放,解决了图片变形问题。 四、新闻、产品详细页新增了上一个、下一个的功能,改善用户体验。 五、在线客服新增了阿里巴巴贸易通在线客服。 六、可在后台设置分享代码,如百度分享和AddThis等。










