標籤:type span log head merge new logs iar 打包
一哥們要實現 php 的線上打包工具,隨手在網上搜尋了一個,但跟哥們的要求不一樣,他的要求是在頁面進行的變數傳遞過來的檔案進行打包並在瀏覽器進行下載,但從網上找來的這個測試了下感覺系統還不錯,代碼量也較少,只不過是對某一個目錄檔案整個的一個打包,夏日部落格遂將好代碼進行分享一下吧,執行個體代碼如下:
<?php $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; } ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <html> <head> <title>線上打包工具</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <form name="form1" method="post" action=""> <hr size="1"> <h3><a href="?">線上打包工具</a></h3> <P> <input type="submit" name="button" value="開始打包" /></P> <P>說明:點開始打包,之後,就是耐心等待打包完成了,根據網站檔案多少,需要的時間可能會很長。打包完成之後,壓縮包會存放在要打包的網站目錄下,以<span style=‘color:red;‘>打包時間+不定長隨機字串+jackfeng.zip</span>這樣命名,請登陸ftp後下載。</P> </form> </body> </html>
文章來源:https://www.xiariboke.com/codes/1595.html
php線上打包工具