作者 开飞机的舒克

圖片下載

... ... @@ -16,6 +16,9 @@ use think\db\exception\BindParamException;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use http\Header;
use think\Env;
use app\api\controller\Login;
/**
* 学生管理
... ... @@ -296,5 +299,61 @@ class Study extends Backend
$this->success();
}
/**
* 下载分享码
*
* @param $ids
* @return void
*/
public function multi($ids = null)
{
$ids = $this->request->param('ids');
$product = new \app\admin\model\Study();
$ids = explode(',', $ids);
$arr = $product->whereIn('id' , $ids)->field('barcode')->select();
foreach ($arr as $v){
$v['barcode'] = substr($v['barcode'],20);
$as = ROOT_PATH.'public/'.$v['barcode'];
$data[]=$as;
}
$url = ROOT_PATH.'public/';
// $data = [
// ROOT_PATH.'public/uploads/QR/20230301/_18.jpg'
// ];
// zip 临时文件
$tmp_dir = $url . 'temp/';
// zip名称
$zip_name = 'quality_'.time().'.zip';
// 打包
$zipName = $this->zip_files($data, $tmp_dir.$zip_name);
//下载
$down = 'http://campus.shs.broing.cn/temp/'.$zip_name;
downloads($down);
}
/**
* 打包成zip
* @param $pathArr
* @param $zipName
* @return array
*/
public function zip_files($pathArr,$zipName)
{
$zip = new \ZipArchive();
if($zip->open($zipName,\ZipArchive::CREATE|\ZipArchive::OVERWRITE)){
foreach($pathArr as $file){
if(!file_exists($file)){
continue;
}
$zip->addFile($file,basename($file)); //向压缩包中添加文件
}
$zip->close();
return $zipName;
}else{
return '';
}
}
}
... ...
... ... @@ -11,7 +11,7 @@
<a href="javascript:;" class="btn btn-success btn-import {:$auth->check('你的权限规则')?'':'hide'}" title="导入" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> 导入</a>
<a href="javascript:;" class="btn btn-danger btn-export {:$auth->check('study/export')?'':'hide'}" title="{:__('Export')}" id="btn-export-file"><i class="fa fa-download"></i> {:__('Export')}</a>
<a class="btn btn-info btn-disabled disabled btn-selected" href="javascript:;"><i class="fa fa-leaf"></i> 批量下载</a>
<a href="#" title="下载分享码" class="btn btn-success btn-disabled download {:$auth->check('study/multi')?'':'hide'} ">下载分享码</a>
<div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}">
<ul class="dropdown-menu text-left" role="menu">
... ...
... ... @@ -548,12 +548,12 @@ EOT;
if (file_exists($filename)) {
unlink($filename);
}
//重新生成文件
//重新生成文件
$zip = new ZipArchive();
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
exit('无法打开文件,或者文件创建失败');
}
// $datalist=array('try.php','zip_class.php');
// $datalist=array('try.php','zip_class.php');
foreach ($datalist as $val) {
if (file_exists($val)) {
$path_parts = pathinfo($val);
... ... @@ -572,4 +572,31 @@ EOT;
$upload_path = str_replace('\\', '/', ROOT_PATH);
return $upload_path . 'public' . $path;
}
/**
*下载小程序码到浏览器
*
* @param string $pic_url 下载路径
*/
function downloads($file)
{
$fileTmp = pathinfo($file);
$fileExt = $fileTmp['extension']; //图片后缀名
$filename =($fileTmp['filename']); //图片名称,可以任务设置图片名称
$saveFileName = ($filename.'.'.$fileExt);
$fp=fopen($file,"r");
//下载文件需要用到的头
Header("Content-type: video/quicktime");
Header("Accept-Ranges: bytes");
Header("Content-Disposition: attachment; filename=".$saveFileName);
$buffer=1024;
$file_count=0;
//向浏览器返回数据
while(!feof($fp)){
$file_con=fread($fp,$buffer);
$file_count+=$buffer;
echo $file_con;
}
fclose($fp);
}
}
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
$('.download').click(function () {
var ids = Table.api.selectedids($("#table"));
window.location.href = '/back.php/study/multi?ids='+ids;
});
var Controller = {
index: function () {
// 初始化表格参数配置
... ... @@ -26,10 +31,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
if (res.code === 1) {
var domain = window.location.href.split(':')[0] + '://' + document.domain;
var url = domain + '/back.php/study/down_file';
var link = document.createElement('a');
link.setAttribute("download", "");
link.href = url;
link.click();
window.location.href = url;
location.reload();
$(".btn-refresh").trigger("click");
}
}
... ...