PHP一键打包压缩目录文件代码示例
2870
PHP一键打包压缩目录文件代码示例,有时候需要对一个文件目录打包整理,网站找到这么一段代码,分享给大家看看:
- <?php
- $button=$_POST['button'];
- if($button=="开始打包")
- {
- $zip = new ZipArchive();
- $filename = "./".date("Y-m-d")."_".md5(time())."_zy.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">
- <P> <input type="submit" name="button" value="开始打包" /></P>
- </form>
- </body>
- </html>
本文网址:https://www.zztuku.com/index.php/detail-11929.html
站长图库 - PHP一键打包压缩目录文件代码示例
申明:如有侵犯,请 联系我们 删除。
您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!