请问一下这个代码需要修改什么地方,现在我就在页面加载的时候通过 self::zip($test)调用了一下那个函数,但是只要一加这一句网页就疯狂重新加载,去掉就好了请问各位大哥该如何修改呢?
<?php
namespace app\admin\controller;
use think\Config;
use think\Exception;
use think\Session;
use think\Db;
use app\admin\model\Crud;
class Download extends Permissions
{
function download()
{
if (request()->isPjax()) {
$search = '';
$tj = '';
if (Session::has('search')) {
if (isset($_POST['search'])) {
if (input('search') === '') {
Session::set('search', null);
}
$search = input('search');
Session::set('search', $search);
$sentence = "(filename like '%$search%')";
} else {
$search = Session::get('search');
$sentence = "(filename like '%$search%')";
}
} else {
if (input('search') !== '') {
$search = input('search');
Session::set('search', $search);
$sentence = "(filename like '%$search%')";
}
}
// 开始时间,结束时间
if (input('start_time') != null && input('end_time') != null) {
// 两个时间都不为空
$s = strtotime(input('start_time') . ' 00:00:00');
$e = strtotime(input('end_time') . ' 23:59:59');
$tj['create_time'][] = array('egt', $s);
$tj['create_time'][] = array('elt', $e);
} else if (input('start_time') != null || input('end_time') != null) {
// 只选了一个时间点
$s = input('start_time') != null ? strtotime(input('start_time') . ' 00:00:00') : '';
$e = input('end_time') != null ? strtotime(input('end_time') . ' 23:59:59') : '';
$tj['create_time'] = input('start_time') == null ? array('elt', $e) : array('egt', $s);
}
$num = input('num') ? input('num') : 10;
$this->assign('num', $num);
// 将选择的参数传递至 HTML
$this->assign(['start' => input('start_time'), 'end' => input('end_time')]);//选择的合同签订时间段
$this->assign('status', input('status'));
$this->assign('low', input('low'));
$this->assign('high', input('high'));
$this->assign('search', $search);
if (!empty($sentence)) {
$download = Db::name('attachment')->where($tj)->where($sentence)->where('use', 'download_paper')->order('id', 'asc')->paginate($num);
$test = Db::name('attachment')->where($tj)->where($sentence)->where('use', 'download_paper')->field('filepath,filename')->select();
} else {
$download = Db::name('attachment')->where($tj)->where('use', 'download_paper')->order('id', 'asc')->paginate($num);
$test = Db::name('attachment')->where($tj)->where('use', 'download_paper')->field('filepath,filename')->select();
}
$page = $download->render();
$this->assign(['download' => $download, 'page' => $page]);
$this->assign(['test' => json_encode($test)]);
$hetong = self::zip($test);
$this->assign('hetong', $hetong);
return $this->fetch();
} else {
Session::delete('search');
$url = '';
$url .= '?page=' . (input('page') ? input('page') : '');
$url .= '&num=' . (input('num') ? input('num') : '');
$url .= '&start_time=' . (input('start_time') ? input('start_time') : '');
$url .= '&end_time=' . (input('end_time') ? input('end_time') : '');
$this->assign('url', $url);
return $this->fetch('page');
}
}
function zip($test)
{
$current = getcwd();
if (count($test) > 0) {
foreach ($test as $k => $v) {
$files = $current . $v['filepath'];
$zip = new \ZipArchive;
$zipName = '\uploads\admin\admin_thumb\\' . time() . '.zip';
if ($zip->open($current .$zipName, \ZipArchive::CREATE) === TRUE) {
$zip->addFile($files, $v['filename']);
}
}
$zip->close();
return $zipName;
}
else{
return 0;
}
}
}
?>
1
ganbuliao 2019-11-20 14:26:41 +08:00
$this->zip($test);
|
4
jay4497 2019-11-20 17:08:29 +08:00
重新加载没看出来哪儿的问题,但是生成压缩文件这个方法就是会循环生成 $test 记录数个压缩文件吧,它重新加载不会停的么,死循环?
|
5
hoyixi 2019-11-20 17:13:08 +08:00
既然一调用这函数就出问题,那就调试这个函数啊,也没几行
|
6
CR7sun OP 找到原因了。。。。,因为压缩文件时间太长,超过了 pjax 默认的最长响应时间,pjax 认定请求失败所以重复刷新,只要把 pjax 的默认最长响应时间改长就行了。
|