header(
"Content-type: text/html; charset=utf-8"
);
require_once
'../config.inc.php'
;
$arrfiles
=
array
(SYS_UPLOAD .
'/1.jpg'
,
SYS_UPLOAD .
'/x.jpg'
,);
$orderNum
=
'888'
;
$downFileName
=
'tieniu.zip'
;
$zipUrl
= create_zip(
$arrfiles
,
$orderNum
);
file_down(
$zipUrl
,
$downFileName
);
function
get_zipname(
$orderNum
) {
$zipName
= SYS_DOWNLOAD .
'/'
.
date
(
'Ym'
) .
'/'
.
$orderNum
.
'_'
.
date
(
"Ymd_Hi"
) .
'.zip'
;
return
$zipName
;
}
function
pack_object() {
}
function
create_zip(
$arrfiles
,
$orderNum
) {
$zipName
= get_zipname(
$orderNum
);
dir_create(dirname(
$zipName
));
$zip
=
new
ZipArchive();
if
(
$zip
->open(
$zipName
, ZIPARCHIVE::CREATE) !== TRUE) {
return
FALSE;
}
foreach
(
$arrfiles
as
$path
) {
if
(
is_file
(
$path
)) {
$zip
->addFile(
$path
,
basename
(
$path
));
}
}
$zip
->close();
return
$zipName
;
}
function
dir_path(
$dirpath
) {
$dirpath
=
str_replace
(
'\\'
,
'/'
,
$dirpath
);
if
(
substr
(
$dirpath
, -1) !=
'/'
)
$dirpath
=
$dirpath
.
'/'
;
return
$dirpath
;
}
function
dir_create(
$path
) {
if
(
is_dir
(
$path
))
return
true;
$dir
=
str_replace
(SYS_DOWNLOAD .
'/'
,
''
,
$path
);
$dir
= dir_path(
$dir
);
$temp
=
explode
(
'/'
,
$dir
);
$cur_dir
= SYS_DOWNLOAD .
'/'
;
$max
=
count
(
$temp
) - 1;
for
(
$i
= 0;
$i
<
$max
;
$i
++) {
$cur_dir
.=
$temp
[
$i
] .
'/'
;
if
(
is_dir
(
$cur_dir
))
continue
;
@
mkdir
(
$cur_dir
);
if
(SYS_CHMOD)
@
chmod
(
$cur_dir
, SYS_CHMOD);
if
(!
is_file
(
$cur_dir
.
'/index.html'
) && !
is_file
(
$cur_dir
.
'/index.php'
))
file_copy(SYS_ROOT .
'/upload/index.html'
,
$cur_dir
.
'/index.html'
);
}
return
is_dir
(
$path
);
}
function
file_copy(
$from
,
$to
) {
dir_create(dirname(
$to
));
if
(
is_file
(
$to
) && SYS_CHMOD)
@
chmod
(
$to
, SYS_CHMOD);
if
(@
copy
(
$from
,
$to
)) {
if
(SYS_CHMOD)
@
chmod
(
$to
, SYS_CHMOD);
return
true;
}
else
{
return
false;
}
}
function
file_down(
$file
,
$filename
=
''
,
$data
=
''
) {
if
(!
$data
&& !
is_file
(
$file
))
exit
;
$filename
=
$filename
?
$filename
:
basename
(
$file
);
$filetype
= file_ext(
$filename
);
$filesize
=
$data
?
strlen
(
$data
) :
filesize
(
$file
);
ob_end_clean();
@set_time_limit(0);
if
(
strpos
(
$_SERVER
[
'HTTP_USER_AGENT'
],
'MSIE'
) !== false) {
header(
'Cache-Control: must-revalidate, post-check=0, pre-check=0'
);
header(
'Pragma: public'
);
}
else
{
header(
'Pragma: no-cache'
);
}
header(
'Expires: '
.
gmdate
(
'D, d M Y H:i:s'
) .
' GMT'
);
header(
'Content-Encoding: none'
);
header(
'Content-Length: '
.
$filesize
);
header(
'Content-Disposition: attachment; filename='
.
$filename
);
header(
'Content-Type: '
.
$filetype
);
if
(
$data
) {
echo
$data
;
}
else
{
readfile(
$file
);
}
exit
;
}
function
file_ext(
$filename
) {
return
strtolower
(trim(
substr
(
strrchr
(
$filename
,
'.'
), 1)));
}
function
listdir(
$start_dir
=
'.'
) {
$files
=
array
();
if
(
is_dir
(
$start_dir
)) {
$fh
= opendir(
$start_dir
);
while
((
$file
= readdir(
$fh
)) !== false) {
if
(
strcmp
(
$file
,
'.'
) == 0 ||
strcmp
(
$file
,
'..'
) == 0)
continue
;
$filepath
=
$start_dir
.
'/'
.
$file
;
if
(
is_dir
(
$filepath
))
$files
=
array_merge
(
$files
, listdir(
$filepath
));
else
array_push
(
$files
,
$filepath
);
}
closedir
(
$fh
);
}
else
{
$files
= false;
}
return
$files
;
}