實現打包功能~輕鬆方便!壓縮比雖比winrar差那麼一點 但是也沒啥關係 畢竟只打包做下載
省下了自己去伺服器上把網站打包 如果伺服器不是自己的就更麻煩了 要讓別人幫忙打下包
複製代碼 代碼如下:
//php壓縮目錄成zip包
//作者:小鋒
$button=$_POST['button'];
if($button=="開始打包")
{
$zip = new ZipArchive();
$filename = "./".date("Y-m-d")."_".md5(time())."_jackfeng.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("無法建立 <$filename>\n");
}
$files = listdir();
foreach($files as $path)
{
$zip->addFile($path,str_replace("./","",str_replace("\\","/",$path)));
}
echo "壓縮完成,共壓縮了: " . $zip->numFiles . "個檔案\n";
$zip->close();
}
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;
}
?>
線上打包工具
http://www.bkjia.com/PHPjc/319366.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319366.htmlTechArticle實現打包功能~輕鬆方便!壓縮比雖比winrar差那麼一點但是也沒啥關係畢竟只打包做下載 省下了自己去伺服器上把網站打包如果伺服器不是自...