// php 文件Zip压缩
function
create_zip(
$files
=
array
(),
$destination
=
""
,
$overwrite
= false) {
if
(
file_exists
(
$destination
) && !
$overwrite
)
return
false;
if
(
is_array
(
$files
)) {
foreach
(
$files
as
$file
) {
if
(
file_exists
(
$file
))
$valid_files
[] =
$file
;
}
}
if
(
count
(
$valid_files
)) {
$zip
=
new
ZipArchive();
if
(
$zip
->open(
$destination
,
$overwrite
? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true)
return
false;
foreach
(
$valid_files
as
$file
)
$zip
->addFile(
$file
,
$file
);
$zip
->close();
return
file_exists
(
$destination
);
}
else
return
false;
}
$files
=
array
(
"a.gif"
,
"b.gif"
,
"c.gif"
);
create_zip(
$files
,
"myzipfile.zip"
, true);