Example #1
0
 /**
  * 打包下载所有文件
  */
 public function ondownAllFile()
 {
     try {
         //获得所有数据
         $avl_data = Model::AvlInfo()->fetchAll();
         if (empty($avl_data)) {
             throw new Exception('没有数据');
         }
         $all_file_path = AppRoot . '/Temp/all_avl';
         if (!file_exists($all_file_path)) {
             mkdir($all_file_path, 0777, true);
         }
         foreach ($avl_data as $value) {
             $folder = $value['create_time'];
             $filePath = AppRoot . '/Temp/' . $folder . '/' . $value['avl_name'];
             if (file_exists($filePath)) {
                 copy($filePath, $all_file_path . '/' . $value['avl_name']);
             }
         }
         exec('cd ' . $all_file_path . '&&zip -r allavl.zip *');
         $zipfile = $all_file_path . '/allavl.zip';
         if (!file_exists($zipfile)) {
             throw new Exception('打包文件失败');
         }
         header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
         header("Content-Description:File Transfer");
         header("Content-type: application/octet-stream");
         //定义数据类型
         header("Content-Length: " . filesize($zipfile));
         header("Content-Disposition: attachment; filename=" . basename($zipfile));
         readfile($zipfile);
         exec('rm -rf ' . $all_file_path);
     } catch (Exception $exc) {
         header('Content-Type: text/html; charset=utf-8');
         exit($exc->getMessage());
     }
 }