本篇文章给大家带来的内容是关于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();
}
相关文章推荐: