PHP Zip壓縮 在線對(duì)文件進(jìn)行壓縮的函數(shù)
更新時(shí)間:2010年05月26日 00:31:29 作者:
PHP在線對(duì)文件進(jìn)行Zip 壓縮函數(shù)代碼,用于使用PHP在線創(chuàng)建ZIP壓縮文件。
復(fù)制代碼 代碼如下:
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
/***** Example Usage ***/
$files=array('file1.jpg', 'file2.jpg', 'file3.gif');
create_zip($files, 'myzipfile.zip', true);
PHP Zip 文件在線解壓縮的函數(shù)代碼
相關(guān)文章
PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能示例
這篇文章主要介紹了PHP實(shí)現(xiàn)生成數(shù)據(jù)字典功能,涉及php針對(duì)mysql常見(jiàn)的連接、數(shù)據(jù)表查詢(xún)、遍歷、table表格構(gòu)成等相關(guān)操作技巧,需要的朋友可以參考下2018-05-05
php+ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)的方法
這篇文章主要介紹了php+ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)的方法,詳細(xì)講述了數(shù)據(jù)庫(kù)的創(chuàng)建、Ajax文件的實(shí)現(xiàn)及PHP調(diào)用方法,需要的朋友可以參考下2014-11-11
php生成4位數(shù)字驗(yàn)證碼的實(shí)現(xiàn)代碼
這篇文章主要介紹了php數(shù)字驗(yàn)證碼的實(shí)現(xiàn)代碼,具有一定借鑒價(jià)值,需要的朋友可以參考下2015-11-11

