没有合适的资源?快使用搜索试试~ 我知道了~
php压缩zip文件
5星 · 超过95%的资源 需积分: 9 51 下载量 74 浏览量
2009-03-12
12:43:35
上传
评论 1
收藏 1KB TXT 举报
温馨提示
试读
2页
在php开发中可以将一个或多个文件压缩为一个zip文件(文件名可以自己定)进行下载或其他处理。
资源推荐
资源详情
资源评论
<?php
//本代码已经测试过了,没有问题,如果你有不懂的地方请留言
//将多个文件压缩为一个zip文件
//一般是要将多个文件打包压缩(当然单个文件就更简单了),所以多个要压缩的文件可以用字符串拼接起来传到函数中(中间用“|”连接)
function getzipfile($getzipfile,$filestr)
{
$zip = new ZipArchive();
//生成的压缩文件
//$filename = "./test112.zip";
$filename = $getzipfile;
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
{
exit("cannot open <$filename>\n");
}
$all_add_file = explode("|",$filestr);
for($i = 0;$i < count($all_add_file) ;$i++)
{
$one_file_name = $all_add_file[$i];
$zip->addFile($one_file_name);
}
//添加的文件
//$zip->addFromString("testfilephp.txt" , "#1 This is a test string added as testfilephp.txt.\n");
//$zip->addFromString("testfilephp2.txt" , "#2 This is a test string added as testfilephp2.txt.\n");
//添加的文件
//$zip->addFile("index.php");
//$zip->addFile("mail_test.php");
//本代码已经测试过了,没有问题,如果你有不懂的地方请留言
//将多个文件压缩为一个zip文件
//一般是要将多个文件打包压缩(当然单个文件就更简单了),所以多个要压缩的文件可以用字符串拼接起来传到函数中(中间用“|”连接)
function getzipfile($getzipfile,$filestr)
{
$zip = new ZipArchive();
//生成的压缩文件
//$filename = "./test112.zip";
$filename = $getzipfile;
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
{
exit("cannot open <$filename>\n");
}
$all_add_file = explode("|",$filestr);
for($i = 0;$i < count($all_add_file) ;$i++)
{
$one_file_name = $all_add_file[$i];
$zip->addFile($one_file_name);
}
//添加的文件
//$zip->addFromString("testfilephp.txt" , "#1 This is a test string added as testfilephp.txt.\n");
//$zip->addFromString("testfilephp2.txt" , "#2 This is a test string added as testfilephp2.txt.\n");
//添加的文件
//$zip->addFile("index.php");
//$zip->addFile("mail_test.php");
iamthebest100
- 粉丝: 0
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页