Login
网站首页 > 文章中心 > 其它

phpzip加密

作者:小编 更新时间:2023-09-18 07:34:53 浏览量:190人看过

zip密码 php

用PHP的zip模块进行压缩加密.

开始

$zipArc?=?new?\ZipArchive();if?($zipArc-open('/home/test.zip',?ZipArchive::CREATE?|?ZipArchive::OVERWRITE)?===?true)?{?//设置密码?注意此处不是加密,仅仅是设置密码

if?(!$zipArc-setPassword('password'))?{??throw?new?RuntimeException('Set?password?failed');

}?//往压缩包内添加文件

$zipArc-addFile('/home/test.png',?'1/test.png');?//加密文件?此处文件名及路径是压缩包内的

}

$zipArc-close();

注意事项

以前,此功能仅设置用于解压缩存档的密码; 它没有将非密码保护的ZipArchive 变成受密码保护的ZipArchive.

提示没有setEncryptionName和setEncryptionIndex方法时,请编译时zip模块时用以下参数

--with-libzip

--enable-zip

待压缩的文件目录,比说说是/home/test/a.png

压缩后,你发现压缩包内的目录结构是/home/test/a.png,

也就是说压缩包原封不动的保持了原来文件的目录.可是我们想自定义压缩包目录怎么办呢?

$a = '/home/test.png';

$b = '1/test.png';//$a是待添加的文件路径 ?$b是压缩包内的路径$zipArc-addFile($a, $b);

php 怎么用zend加密

可以加密就可以解密.

解密ZEND加密后的PHP文件:

zend加密php文件解密工具Dezender可以做到.

然后就可以看见文件目录下面会多出一个文件 ? ?文件名.de.php

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

php

//需开启配置?php_zip.dll

//phpinfo();

function?get_zip_originalsize($filename,?$path)?{

//先判断待解压的文件是否存在

if(!file_exists($filename)){

die("文件?$filename?不存在!");

}?

$starttime?=?explode('?',microtime());?//解压开始的时间

//打开压缩包

$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)){

//如果不是目录,则写入文件

if(!is_dir($file_name)){

//读取这个文件

$file_size?=?zip_entry_filesize($dir_resource);

$file_content?=?zip_entry_read($dir_resource,$file_size);

file_put_contents($file_name,$file_content);

}else{

//关闭当前

zip_entry_close($dir_resource);

//关闭压缩包

zip_close($resource);?

$endtime?=?explode('?',microtime());?//解压结束的时间

$thistime?=?$endtime[0]◆$endtime[1]-($starttime[0]◆$starttime[1]);

echo?"p解压完毕!,本次解压花费:$thistime?秒./p";

php怎样实现对zip文件的加密和解密

使用PHPZip类就可以解决的.以下是网上找到的例子.

$z?=?new?PHPZip();

$zipfile?=?TEMP."/photocome_".$groupid.".zip";

$z-Zip($zipfiles,?$zipfile);

#?

#?Makes?zip?archive

#

#?Based?on?"Zip?file?creation?class",?uses?zLib

class?PHPZip

{

function?Zip($dir,?$zipfilename)

if?(@function_exists('gzcompress'))

{?

$curdir?=?getcwd();

if?(is_array($dir))?

$filelist?=?$dir;

else?

$filelist?=?$this?-?GetFileList($dir);

if?((!empty($dir))(!is_array($dir))(file_exists($dir)))?chdir($dir);

else?chdir($curdir);

if?(count($filelist)0)

foreach($filelist?as?$filename)

if?(is_file($filename))

$fd?=?fopen?($filename,?"r");

$content?=?fread?($fd,?filesize?($filename));

fclose?($fd);

if?(is_array($dir))?$filename?=?basename($filename);

$this?-?addFile($content,?$filename);

$out?=?$this?-?file();

chdir($curdir);

$fp?=?fopen($zipfilename,?"w");

fwrite($fp,?$out,?strlen($out));

fclose($fp);

return?1;

else?return?0;

function?GetFileList($dir)

if?(file_exists($dir))

$args?=?func_get_args();

$pref?=?$args[1];

$dh?=?opendir($dir);

while($files?=?readdir($dh))

if?(($files!=".")($files!=".."))?

if?(is_dir($dir.$files))?

chdir($dir.$files);

$file?=?array_merge($file,?$this?-?GetFileList("",?"$pref$files/"));

else?$file[]=$pref.$files;

closedir($dh);

return?$file;

var?$datasec?=?array();

var?$ctrl_dir??=?array();

var?$old_offset?=?0;

/**

*?Converts?an?Unix?timestamp?to?a?four?byte?DOS?date?and?time?format?(date

*?in?high?two?bytes,?time?in?low?two?bytes?allowing?magnitude?comparison).

*

*?@param?integer?the?current?Unix?timestamp

*?@return?integer?the?current?date?in?a?four?byte?DOS?format

*?@access?private

*/

$timearray?=?($unixtime?==?0)?getdate()?:?getdate($unixtime);

$timearray['mon']??=?1;

$timearray['mday']?=?1;

$timearray['hours']?=?0;

$timearray['minutes']?=?0;

$timearray['seconds']?=?0;

}?//?end?if

*?Adds?"file"?to?archive

*?@param?string?file?contents

*?@param?string?name?of?the?file?in?the?archive?(may?contains?the?path)

*?@param?integer?the?current?timestamp

*?@access?public

function?addFile($data,?$name,?$time?=?0)

$name??=?str_replace('',?'/',?$name);

.?'x'?.?$dtime[0]?.?$dtime[1];

eval('$hexdtime?=?"'?.?$hexdtime?.?'";');

$fr?.=?"x00x00";??//?gen?purpose?bit?flag

$fr?.=?$hexdtime;???//?last?mod?time?and?date

//?"local?file?header"?segment

$unc_len?=?strlen($data);

$zdata?=?gzcompress($data);

$c_len?=?strlen($zdata);

$fr?.=?pack('V',?$c_len);???//?compressed?filesize

$fr?.=?pack('V',?$unc_len);??//?uncompressed?filesize

$fr?.=?pack('v',?strlen($name));?//?length?of?filename

$fr?.=?pack('v',?0);???//?extra?field?length

$fr?.=?$name;

//?"file?data"?segment

$fr?.=?$zdata;

//?"data?descriptor"?segment?(optional?but?necessary?if?archive?is?not

//?served?as?file)

$fr?.=?pack('V',?$unc_len);???//?uncompressed?filesize

//?add?this?entry?to?array

$this?-?datasec[]?=?$fr;

$new_offset??=?strlen(implode('',?$this-datasec));

//?now?add?to?central?directory?record

$cdrec?.=?"x00x00";???//?version?made?by

$cdrec?.=?"x00x00";???//?gen?purpose?bit?flag

$cdrec?.=?$hexdtime;????//?last?mod?time?date

$cdrec?.=?pack('V',?$c_len);??//?compressed?filesize

$cdrec?.=?pack('V',?$unc_len);??//?uncompressed?filesize

$cdrec?.=?pack('v',?strlen($name)?);?//?length?of?filename

$cdrec?.=?pack('v',?0?);???//?extra?field?length

$cdrec?.=?pack('v',?0?);???//?file?comment?length

$cdrec?.=?pack('v',?0?);???//?disk?number?start

$cdrec?.=?pack('v',?0?);???//?internal?file?attributes

$cdrec?.=?pack('V',?$this?-?old_offset?);?//?relative?offset?of?local?header

$this?-?old_offset?=?$new_offset;

$cdrec?.=?$name;

//?optional?extra?field,?file?comment?goes?here

//?save?to?central?directory

$this?-?ctrl_dir[]?=?$cdrec;

}?//?end?of?the?'addFile()'?method

*?Dumps?out?file

*?@return?string?the?zipped?file

function?file()

$data?=?implode('',?$this?-?datasec);

$ctrldir?=?implode('',?$this?-?ctrl_dir);

return

$data?.

$ctrldir?.

$this?-?eof_ctrl_dir?.

pack('v',?sizeof($this?-?ctrl_dir))?.?//?total?#?of?entries?"on?this?disk"

pack('v',?sizeof($this?-?ctrl_dir))?.?//?total?#?of?entries?overall

pack('V',?strlen($ctrldir))?.???//?size?of?central?dir

pack('V',?strlen($data))?.???//?offset?to?start?of?central?dir

"x00x00";??????//?.zip?file?comment?length

}?//?end?of?the?'file()'?method

}?//?end?of?the?'PHPZip'?class

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文件里面?

如何在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

以上就是土嘎嘎小编为大家整理的phpzip加密相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章