《PHP應用:php簡單創建zip壓縮文件的方法》要點:
本文介紹了PHP應用:php簡單創建zip壓縮文件的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP編程本文實例講述了php簡單創建zip壓縮文件的辦法.分享給大家供大家參考,具體如下:
PHP編程
/* 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;
}
}
PHP編程使用辦法:
PHP編程
$files_to_zip = array(
'preload-images/1.jpg',
'preload-images/2.jpg',
'preload-images/5.jpg',
'kwicks/ringo.gif',
'rod.jpg',
'reddit.gif'
);
//if true, good; if false, zip creation failed
$result = create_zip($files_to_zip,'my-archive.zip');
PHP編程更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP操作zip文件及壓縮技巧總結》、《php文件操作總結》、《php正則表達式用法總結》、《PHP+ajax技巧與應用小結》、《PHP運算與運算符用法總結》、《PHP網絡編程技巧總結》、《PHP基本語法入門教程》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
PHP編程希望本文所述對大家PHP程序設計有所贊助.
《PHP應用:php簡單創建zip壓縮文件的方法》是否對您有啟發,歡迎查看更多與《PHP應用:php簡單創建zip壓縮文件的方法》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/6820.html