时间:2021-05-26
本文实例讲述了php生成zip文件类。分享给大家供大家参考。具体如下:
<?php class zipFile { public $files = array(); public $settings = NULL; public $fileInfo = array ( "name" => "", "numFiles" => 0, "fullFilePath" => "" ); private $fileHash = ""; private $zip = ""; public function __construct($settings) { $this->zipFile($settings); } public function zipFile($settings) { $this->zip = new ZipArchive(); $this->settings = new stdClass(); foreach ($settings as $k => $v) { $this->settings->$k = $v; } } public function create() { $this->fileHash = md5(implode(",", $this->files)); $this->fileInfo["name"] = $this->fileHash . ".zip"; $this->fileInfo["numFiles"] = count($this->files); $this->fileInfo["fullFilePath"] = $this->settings->path . "/" . $this->fileInfo["name"]; if (file_exists($this->fileInfo["fullFilePath"])) { return array ( false, "already created: " . $this->fileInfo["fullFilePath"] ); } else { $this->zip->open($this->fileInfo["fullFilePath"], ZIPARCHIVE::CREATE); $this->addFiles(); $this->zip->close(); return array ( true, "new file created: " . $this->fileInfo["fullFilePath"] ); } } private function addFiles() { foreach ($this->files as $k) { $this->zip->addFile($k, basename($k)); } }}$settings = array ( "path" => dirname(__FILE__) );$zipFile = new zipFile($settings);$zipFile->files = array ( "./images/navoff.jpg", "./images/navon.jpg" );list($success, $error) = $zipFile->create();if ($success === true) { //success}else { //error because: $error}?>希望本文所述对大家的php程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了php实现的zip文件内容比较类。是一个非常实用的PHP类文件。分享给大家供大家参考。具体分析如下:该phpzip文件比较类主要实现比较两个zip
本文实例讲述了PHP生成RSS文件类文件。分享给大家供大家参考。具体如下:PHPRSS生成类实例代码如下:复制代码代码如下:additem('rssclass'
这里的下载是生成zip包进行下载,所以需要PHP的ZipArchive()类,使用本类,linux需开启zlib,windows需取消php_zip.dll前的
本文实例讲述了PHP生成zip压缩包的常用方法。分享给大家供大家参考,具体如下:压缩一个文件我们将一个文件生成一个压缩包。open($filename,ZipA
php读取zip文件(删除文件,提取文件,增加文件)实例从zip压缩文件中提取文件复制代码代码如下:open('jQuery五屏上下滚动焦点图代码.zip')=