php 文件列表打包小工具

来源:互联网 发布:lhgdialog.js 编辑:程序博客网 时间:2024/06/16 19:26

可以把 php5ts.dll php_zip.dll php.ini 放在一个目录

<?php/* *读list.txt 文件 生成 zip文件的函数 需要zip 库 支持 *list.txt里每一行   *请将list.txt 放到web的根目录或者 指定其 路径 *请将本程序 放到web的根目录或者 指定 生成 zip 文件的 路径 */if (!extension_loaded('zip')) {dl('php_zip.dll');}$file_list="list.txt";//文件列表 if(!file_exists($file_list))exit('list does not exists!');$fileArray=file($file_list);foreach($fileArray as $key => $path){$fileArray[$key]= $path;}$tmp_file= add_file2zip($fileArray,"../pic/","pic_root");echo "/nok:  ".$tmp_file." /n";/*fileArray Array 需要压缩的文件列表 一维数组形式basePath起始目录preName保存的文件名前辍saveFile保存的文件名返回压缩后的文件*/function add_file2zip($fileArray,$basePath,$preName="",$saveFile=""){//错误检查if(!is_array($fileArray))return('list does not exists!');if(empty($saveFile))$saveFile = $preName."_".date("Ymd_H");$saveFile.=".zip";if(file_exists($saveFile)){unlink($saveFile);}//启动压缩$zip = new ZipArchive();if ($zip->open($saveFile, ZIPARCHIVE::CREATE)!==TRUE) {exit("cannot open <$saveFile>/n");}//压入文件foreach($fileArray as $key => $path){$path= trim($path);if(empty($path))continue;if(!$zip->addFile($basePath.$path,$path)){echo ">/n [error]".$path." ";}elseecho "/nadd:  ";echo $basePath.$path;}$zip->close();return $saveFile;}?>