导航:首页 > 编程语言 > php创建zip

php创建zip

发布时间:2022-10-03 07:41:23

A. php如何开启ZIP模块

第一步、找到php.ini文件

第二部、用记事本打开

第三步、使用ctrl键+F键搜索;extension=php_zip.dll

第四步、去除extension前面的分号“;”,如extension=php_zip.dll

第五步、保存重启Apache或其他服务器。

如图:

B. 如何安装 php 的zip模块

zip 是php的一个扩展,用于支持zip文件压缩解压
按照下面的步骤配置:
1. 用记事本编辑你的 php.ini 文件,搜索 zip.dll 然后把这一行前面的 ; (分号)去掉,保存 php.ini 注意,这一行的上面应该有很多诸如 ;php_***.dll 的,否则搜索的位置不正确,再次搜索
2. 重新启动你的 WEB 服务器。IIS直接在 开始 运行 里面输入 iisreset, Apache 通过管理器先停止再启动即可

C. PHP网页上打包文件生成压缩文件zip,并弹出下载

既然你只是想学习如何打包.


那我重点就回答你这一块,正好我刚刚用到;

$filename="./".date('YmdH').".zip";//最终生成的文件名(含路径)
//生成文件
$zip=newZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit('无法打开文件,或者文件创建失败');
}

//$fileNameArr就是一个存储文件路径的数组比如array('/a/1.jpg,/a/2.jpg....');

foreach($fileNameArras$val){
$zip->addFile($val,basename($val));//第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下
}
$zip->close();//关闭

//下面是输出下载;
header("Cache-Control:max-age=0");
header("Content-Description:FileTransfer");
header('Content-disposition:attachment;filename='.basename($filename));//文件名
header("Content-Type:application/zip");//zip格式的
header("Content-Transfer-Encoding:binary");//告诉浏览器,这是二进制文件
header('Content-Length:'.filesize($filename));//告诉浏览器,文件大小
@readfile($filename);//输出文件;

D. 如何用PHP创建一个加密的zip压缩文件

/* creates a compressed zip file */function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; }}

E. PHP-php生成zip压缩文件如何给该文件加解压缩密码

<?php
//需开启配置php_zip.dll
//phpinfo();
header("Content-type:text/html;charset=utf-8");
functionget_zip_originalsize($filename,$path){
//先判断待解压的文件是否存在
if(!file_exists($filename)){
die("文件$filename不存在!");
}
$starttime=explode('',microtime());//解压开始的时间

//将文件名和路径转成windows系统默认的gb2312编码,否则将会读取不到
$filename=iconv("utf-8","gb2312",$filename);
$path=iconv("utf-8","gb2312",$path);
//打开压缩包
$resource=zip_open($filename);
$i=1;
//遍历读取压缩包里面的一个个文件
while($dir_resource=zip_read($resource)){
//如果能打开则继续
if(zip_entry_open($resource,$dir_resource)){
//获取当前项目的名称,即压缩包里面当前对应的文件名
$file_name=$path.zip_entry_name($dir_resource);
//以最后一个“/”分割,再用字符串截取出路径部分
$file_path=substr($file_name,0,strrpos($file_name,"/"));
//如果路径不存在,则创建一个目录,true表示可以创建多级目录
if(!is_dir($file_path)){
mkdir($file_path,0777,true);
}
//如果不是目录,则写入文件
if(!is_dir($file_name)){
//读取这个文件
$file_size=zip_entry_filesize($dir_resource);
//最大读取6M,如果文件过大,跳过解压,继续下一个
if($file_size<(1024*1024*6)){
$file_content=zip_entry_read($dir_resource,$file_size);
file_put_contents($file_name,$file_content);
}else{
echo"<p>".$i++."此文件已被跳过,原因:文件过大,->".iconv("gb2312","utf-8",$file_name)."</p>";
}
}
//关闭当前
zip_entry_close($dir_resource);
}
}
//关闭压缩包
zip_close($resource);
$endtime=explode('',microtime());//解压结束的时间
$thistime=$endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
$thistime=round($thistime,3);//保留3为小数
echo"<p>解压完毕!,本次解压花费:$thistime秒。</p>";
}
$size=get_zip_originalsize('20131101.zip','temp/');
?>

F. 如何在PHP中创建压缩的RAR文件

$filename = "./" . date ( 'YmdH' ) . ".zip"; // 最终生成的文件名(含路径)
// 生成文件
$zip = new ZipArchive (); // 使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
if ($zip->open ( $filename, ZIPARCHIVE::CREATE ) !== TRUE) {
exit ( '无法打开文件,或者文件创建失败' );
}

//$fileNameArr 就是一个存储文件路径的数组 比如 array('/a/1.jpg,/a/2.jpg....');

foreach ( $fileNameArr as $val ) {
$zip->addFile ( $val, basename ( $val ) ); // 第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下
}
$zip->close (); // 关闭

G. 为什么php创建zip文件不管用

请参考php手册,函数特点-压缩与归档扩展部分

下面是手册实例一:

<?php

$zip=newZipArchive();
$filename="./test112.zip";

if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit("cannotopen<$filename> ");
}

$zip->addFromString("testfilephp.txt".time(),"#.txt. ");
$zip->addFromString("testfilephp2.txt".time(),"#.txt. ");
$zip->addFile($thisdir."/too.php","/testfromfile.php");
echo"numfiles:".$zip->numFiles." ";
echo"status:".$zip->status." ";
$zip->close();
?>

H. php ZipArchive 能否在指定目录生成压缩包

当然可以啊,亲


下面代码就是在/tmp目录下生成aaaa.zip文件

$zip=newZipArchive();
$zip->open('/tmp/aaaa.zip',ZipArchive::CREATE);
$zip->addEmptyDir('dir1');
$zip->close();

I. php如何生成自解压文件

php ZipArchive 能否在指定目录生成压缩包

初步接触ZipArchive , 目前发现 ZipArchive类生成的zip压缩包是存储在 ppublic function backupfiles(){ $filename = "backups/". time().".zip"; $zip = new \ZipArchive(); $zip->open($filename,\ZipArchive::CREATE); $path = 'demo';//指定的目录 $this->addFileToZip($path, $zip); } public function addFileT

如何用PHP创建一个加密的zip压缩文件

/* creates a compressed zip file */function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && 。

PHP-php生成zip压缩文件如何给该文件加解压缩密码
php如何压缩一个文件夹里面所有的文件到zip文件里面?

//函数:文件压缩//压缩参数:需要压缩的文件或文件夹(文件可为数组),压缩后的zip文件名及存放路径,压缩类型1:文件夹2:文件,后续操作1:压缩后下载;2:存放在服务器上(默认为/@Upload下)//压缩文件夹示例:Tozip("./","../".date("d-H-i-s").".zip",1

如何在PHP中创建压缩的RAR文件

$filename = "./" . date ( 'YmdH' ) . ".zip"; // 最终生成的文件名(含路径) // 生成文件 $zip = new ZipArchive (); // 使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open ( $filename, ZIPARCHIVE::CREATE ) 。

看你的内存是多大了,只要你的虚拟内存和物理内存够大。

怎样用php压缩解压rar,zip文件?

要用PHP压缩解压文件,常用的方法是调用命令行去执行解压缩操作 可以用exec() 、system()等函数调用shell命令 Linux下解压缩命令是tar [-cxtzjvfpPN] 文件与目录,tar命令可以压缩解压.tar、.gz、.tar.gz、.tgz、.bz

请高手指点:PHP 如何解压缩zip格式压缩的文件或压zip格式压缩了几个文件,或压缩了一个文件夹,文件夹里有多个文件, 现/** * PHP在线压缩/解压实例 */ date_default_timezone_set('prc'); $zip = new engine_compress_decompress(); if (isset($_POST)) { $sourcePath = ''; //默认位置 if (isset($_FILES['upfile'])) //上传文件 { $stmp = $zip->fileUpload('upf

以上就是CSS布局HTML为大家整理的php生成zip压缩文件的方法详解 技术分享内容,如果觉得小编的资源对您有帮助 不要忘记分享给您身边的朋友哦!

J. 创建一个加密的ZIP文件的PHP问题,怎么解决

官网类:

classHZip
{
/**
*Addfilesandsub-directoriesinafoldertozipfile.
*@paramstring$folder
*@paramZipArchive$zipFile
*@paramint$.
*/
($folder,&$zipFile,$exclusiveLength){
$handle=opendir($folder);
while(false!==$f=readdir($handle)){
if($f!='.'&&$f!='..'){
$filePath="$folder/$f";
//.
$localPath=substr($filePath,$exclusiveLength);
if(is_file($filePath)){
$zipFile->addFile($filePath,$localPath);
}elseif(is_dir($filePath)){
//Addsub-directory.
$zipFile->addEmptyDir($localPath);
self::folderToZip($filePath,$zipFile,$exclusiveLength);
}
}
}
closedir($handle);
}

/**
*Zipafolder(includeitself).
*Usage:
*HZip::zipDir('/path/to/sourceDir','/path/to/out.zip');
*
*@paramstring$.
*@paramstring$outZipPathPathofoutputzipfile.
*/
publicstaticfunctionzipDir($sourcePath,$outZipPath)
{
$pathInfo=pathInfo($sourcePath);
$parentPath=$pathInfo['dirname'];
$dirName=$pathInfo['basename'];

$z=newZipArchive();
$z->open($outZipPath,ZIPARCHIVE::CREATE);
$z->addEmptyDir($dirName);
self::folderToZip($sourcePath,$z,strlen("$parentPath/"));
$z->close();
}
}
使用此类可以添加文件夹
Hzip::zipDir(‘d://www/aa/’,d://aa.zip);
如果添加多个文件夹到一个zip包需要重复调用
如果想继续在zip包中增加文件:
$zip=newZipArchive();
$zip->open(d://aa.zip)
$zip->addFile('d://www/aa.txt','aa.txt');
如果需要增加多个使用循环添加
$zip->close();
<?php
/**
*CreatedbyPhpStormsite:www.5wx.org.
*User:tc
*/

classZip
{
public$pathExe;
public$agent='linux';
publicfunction__construct(){
$this->pathExe=dirname(__FILE__);
$agent=strtolower(PHP_OS);
if(strstr($agent,'win')){
$this->agent='win';
}
}

publicfunctionzip($sourcePath,$fileList=array(),$outPath,$zipName,$password='',$relative="../../../vendor/Zip/"){
try{
$fileStr=implode("",$fileList);
chdir($sourcePath);
$sourcePath=$this->pathDeal($sourcePath);
$zipbool=true;
if($zipbool){
if($this->agent=='win'){
if($password==''){
exec('"'.$this->pathExe.DIRECTORY_SEPARATOR.'zip.exe"'."-q-r".$zipName."".$fileStr);
}else{
exec('"'.$this->pathExe.DIRECTORY_SEPARATOR.'zip.exe"'."-q-r-P".$password."".$zipName."".$fileStr);
}
}else{
if($password==''){
exec("zip-q-r".$zipName."".$fileStr);
}else{
exec("zip-q-r-P".$password."".$zipName."".$fileStr);
}
}
$outPath=$this->pathDeal($outPath);
if(file_exists($sourcePath.DIRECTORY_SEPARATOR.$zipName)){
$bool=($sourcePath.DIRECTORY_SEPARATOR.$zipName,$outPath.DIRECTORY_SEPARATOR.$zipName);
if($bool){
returnjson_encode(array('result'=>true,'message'=>''));
}else{
returnjson_encode(array('result'=>false,'message'=>'zipisexistbutnottooutpath'));
}
}else{
returnjson_encode(array('result'=>false,'message'=>'ziperror'));
}
}else{
returnjson_encode(array('result'=>false,'message'=>'zipcommanderror'));
}
}catch(Exception$e){
returnjson_encode(array('result'=>true,'message'=>json_encode($e)));
}
}
protectedfunctionpathDeal($path){
$lastword=substr($path,-1);
if($lastword==DIRECTORY_SEPARATOR){
$path=substr($path,0,-1);
}
return$path;
}

publicfunctionunzip($sourceZip,$destination,$password){
try{
if($this->agent=='win'){
chdir($this->pathExe);
exec("unzip.exe-o-P".$password."".'"'.$sourceZip.'"'."-d".'"'.$destination.'"',$res,$return);
}else{
exec("unzip-o-P".$password."".$sourceZip."-d".$destination,$res,$return);
}

returnjson_encode(array('result'=>true,'message'=>''));
}catch(Exception$e){
returnjson_encode(array('result'=>true,'message'=>json_encode($e)));
}
}
}

阅读全文

与php创建zip相关的资料

热点内容
老外从墙壁穿越的电影 浏览:813
下人电影完整版下载 浏览:589
云服务器下载服务 浏览:241
pdf如何插入页码 浏览:637
ps选择命令大全 浏览:826
qq聊天记录恢复文件夹 浏览:646
电脑公共盘加密码 浏览:459
韩国电影两个字 浏览:971
鸿蒙系统怎么给App加速 浏览:190
女主叫男主三叔姓战 浏览:377
骁骑校全部小说顺序 浏览:394
如何将iphone手机照片转到安卓手机 浏览:31
从本地邮件到服务器是什么协议 浏览:226
外国片公交车男女主 浏览:234
瓦房店新玛特有电影院吗 浏览:933
免费观看网页版 浏览:622
叶子楣徐锦江演的电影 浏览:40
一级建造师法规pdf 浏览:496
phpshiro 浏览:161
无忧云服务器放行 浏览:634