|
@@ -811,6 +811,10 @@ if (!function_exists('excelSaveBatch')) {
|
|
|
{
|
|
|
|
|
|
$urls = [];
|
|
|
+ $dir = root_path() . 'public/storage/report/' . date("YmdHis") . "/";
|
|
|
+ if (!is_dir($dir)) {
|
|
|
+ mkdir($dir, 0777, true);
|
|
|
+ }
|
|
|
foreach ($datas as $item) {
|
|
|
|
|
|
$objPHPExcel = new PHPExcel();
|
|
@@ -842,10 +846,7 @@ if (!function_exists('excelSaveBatch')) {
|
|
|
$file = $item['filename'] . ".xls";
|
|
|
//$fileName .= "_" . date("Y_m_d", Request()->instance()->time()) . ".xls";
|
|
|
//$fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表
|
|
|
- $dir = root_path() . 'public/storage/report/' . date("YmdHis") . "/";
|
|
|
- if (!is_dir($dir)) {
|
|
|
- mkdir($dir, 0777, true);
|
|
|
- }
|
|
|
+
|
|
|
$objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表
|
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
|
|
$objWriter->save($dir . $file); // 文件通过浏览器下载
|
|
@@ -863,25 +864,24 @@ if (!function_exists('excelSaveBatch')) {
|
|
|
mkdir($saveDir, 0777, true);
|
|
|
}
|
|
|
|
|
|
- $datetime = date("Y-m-d H:i:s");
|
|
|
+ $datetime = date("YmdHis");
|
|
|
$file_dir = $saveDir . $datetime . ".zip";
|
|
|
# 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
|
|
|
$zip = new \ZipArchive ();
|
|
|
# 5.2 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
|
|
|
- if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !==
|
|
|
- true) echo '无法打开文件或者文件创建失败';
|
|
|
+ if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !== true) echo '无法打开文件或者文件创建失败';
|
|
|
|
|
|
# 5.3 批量写入压缩包
|
|
|
+// $zip->addEmptyDir($fileName);//往zip压缩包写入空目录
|
|
|
foreach ($urls as $fileName) {
|
|
|
- $zip->addEmptyDir($fileName);
|
|
|
+ @$zip->addFile($fileName);
|
|
|
}
|
|
|
// @$zip->addFile($v['file_path'], 'resume'.DIRECTORY_SEPARATOR.basename($headername));
|
|
|
- @$zip->addFile($url, $fileName . DIRECTORY_SEPARATOR . basename($url));
|
|
|
# 5.4 关闭压缩包写入
|
|
|
$zip->close();
|
|
|
|
|
|
- @deldir($dir);
|
|
|
- # 6. 检查文件是否存在,并输出文件
|
|
|
+ @deldir($dir);//删除已生成的文件及目录
|
|
|
+ //6. 检查文件是否存在,并输出文件
|
|
|
if (!file_exists($file_dir)) echo '压缩包文件不存在';
|
|
|
|
|
|
ob_clean();
|
|
@@ -892,8 +892,8 @@ if (!function_exists('excelSaveBatch')) {
|
|
|
header("Content-Type: application/octet-stream"); # 流文件输出
|
|
|
header("Content-Transfer-Encoding: binary"); # 告诉浏览器,这是二进制文件
|
|
|
header('Content-Length: ' . filesize($file_dir)); # 告诉浏览器,文件大小
|
|
|
- readfile($file_dir); # 输出文件
|
|
|
- @ unlink($file_dir);
|
|
|
+ readfile($file_dir);//输出文件
|
|
|
+ @unlink($file_dir);
|
|
|
exit();
|
|
|
}
|
|
|
}
|