请问一下这个代码需要修改什么地方,现在我就在页面加载的时候通过 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;
}
}
}
?>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.