public
static
function
downFile(
$id
,
$admin_id
,
$cid
,
$type
)
{
$company
= checkAdminCompany(
$admin_id
,
$cid
);
if
(!
$company
) {
return
[
'status' => -4,
'statusMsg' => '公司不存在'
];
}
if
(
$type
=='file') {
$checkFileRole
= self::checkFileRole(
$admin_id
,
$cid
,
$id
);
if
(!
$checkFileRole
) {
return
[
'status' => 777,
'statusMsg' => '没有操作权限'
];
}
$select_sql
=
"SELECT * FROM cloud_storage WHERE id in ($id)"
;
send_execute_sql(
$select_sql
,
$fileInfo
);
}
elseif
(
$type
== 'list') {
$checkRole
= self::checkRole(
$admin_id
,
$cid
,
$id
);
if
(!
$checkRole
) {
return
[
'status' => '777',
'statusMsg' => '没有操作权限'
];
}
$select_sql
=
"SELECT * FROM cloud_storage WHERE list_id = $id"
;
send_execute_sql(
$select_sql
,
$fileInfo
);
}
if
(
empty
(
$fileInfo
)) {
return
[
'status' => -400,
'statusMsg' => '文件不存在'
];
}
foreach
(
$fileInfo
as
$key
=>
$value
) {
$paths
[
$key
] =
$fileInfo
[
$key
]['path'];
}
$filename
= 'logs/down/test.zip';
if
(!
file_exists
(
$filename
)){
$zip
=
new
ZipArchive();
if
(
$zip
->open(
$filename
, ZipArchive::CREATE)==TRUE) {
foreach
(
$paths
as
$val
){
if
(
file_exists
(
$val
)){
$zip
->addFile(
$val
,
basename
(
$val
));
}
}
$zip
->close();
}
}
if
(!
file_exists
(
$filename
)){
exit
(
"无法找到文件"
);
}
header(
"Cache-Control: public"
);
header(
"Content-Description: File Transfer"
);
header('Content-disposition: attachment; filename='.
basename
(
$filename
));
header(
"Content-Type: application/zip"
);
header(
"Content-Transfer-Encoding: binary"
);
header('Content-Length: '.
filesize
(
$filename
));
ob_clean();
flush
();
@readfile(
$filename
);
unlink(
$fileurl
);
exit
;
}