您好,欢迎访问一九零五行业门户网

一个php 生成zip文件的类

, 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, zip
其它类似信息

推荐信息