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 foreach遍歷多維數(shù)組實(shí)現(xiàn)方式
這篇文章主要為大家詳細(xì)介紹了PHP foreach遍歷多維數(shù)組實(shí)現(xiàn)方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11PHP小偷程序的設(shè)計(jì)與實(shí)現(xiàn)方法詳解
這篇文章主要介紹了PHP小偷程序的設(shè)計(jì)與實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了php基于HTML解析類實(shí)現(xiàn)小偷程序抓取圖片的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2016-10-10PHP下用rmdir實(shí)現(xiàn)刪除目錄的三種方法小結(jié)
PHP本身有一個(gè)rmdir()函數(shù)可以用來刪除目錄,不過要求必須是空目錄,本文列舉了三種方法。1、遞規(guī)法;2、系統(tǒng)調(diào)用法;3、循環(huán)法 。2008-04-04php 時(shí)間time與日期date之間的使用詳解及區(qū)別
PHP中有time函數(shù),也有date函數(shù),這兩個(gè)函數(shù)在使用時(shí)候的區(qū)別很明顯。但更應(yīng)注意,time和date是兩個(gè)完全不時(shí)的格式,當(dāng)然還有一種字符串格式。本文重點(diǎn)介紹這幾者的區(qū)別。2016-11-11