php 文件列表打包小工具

可以把 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." ";

		}

		else

			echo "/nadd:  ";

		echo $basePath.$path;

	}

	$zip->close();

	return $saveFile;

}



?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值