- /*
- 作成者: Matt Ford
-
- 目的: zip ファイルを作成する基本クラス
- */
-
-
-
- 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 -> ファイルハッシュ 。 ".zip";
- $this->fileInfo["numFiles"] = count($this->files);
- $this->fileInfo["fullFilePath"] = $this->settings->gt;パス 。 「/」。 $this->fileInfo["name"];
- if (file_exists($this->fileInfo["fullFilePath"])) {
- return array (
- false,
- "すでに作成されています: " . $this-> fileInfo["fullFilePath"]
- );
- }
- else {
- $this->zip->open($this->fileInfo["fullFilePath"], ZIPARCHIVE::CREATE);
- $this-> addFiles();
- $this->zip->close();
- return array (
- true,
- "新しいファイルが作成されました: " . $this->fileInfo["fullFilePath"]
- );
- }
- }
-
- プライベート関数 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
- }
- ?>
复制代码
|