国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php生成zip文件類實例

2024-05-04 21:56:05
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php生成zip文件類,實例分析了php操作zip文件的技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了php生成zip文件類。分享給大家供大家參考。具體如下:

  1. <?php 
  2.  /* 
  3.   By:   Matt Ford 
  4.   Purpose: Basic class to create zipfiles 
  5.  */ 
  6. class zipFile { 
  7.  public $files = array(); 
  8.  public $settings = NULL; 
  9.  public $fileInfo = array ( 
  10.    "name" => ""
  11.    "numFiles" => 0, 
  12.    "fullFilePath" => "" 
  13.   ); 
  14.  private $fileHash = ""
  15.  private $zip = ""
  16.  public function __construct($settings) { 
  17.   $this->zipFile($settings); 
  18.  } 
  19.  public function zipFile($settings) { 
  20.   $this->zip = new ZipArchive(); 
  21.   $this->settings = new stdClass(); 
  22.   foreach ($settings as $k => $v) { 
  23.    $this->settings->$k = $v
  24.   } 
  25.  } 
  26.  public function create() { 
  27.   $this->fileHash = md5(implode(","$this->files)); 
  28.   $this->fileInfo["name"] = $this->fileHash . ".zip"
  29.   $this->fileInfo["numFiles"] = count($this->files); 
  30.   $this->fileInfo["fullFilePath"] = $this->settings->path .  
  31.   "/" . $this->fileInfo["name"]; 
  32.   if (file_exists($this->fileInfo["fullFilePath"])) { 
  33.    return array ( 
  34.      false, 
  35.      "already created: " . $this->fileInfo["fullFilePath"
  36.      ); 
  37.   } 
  38.   else { 
  39.    $this->zip->open($this->fileInfo["fullFilePath"], ZIPARCHIVE::CREATE); 
  40.    $this->addFiles(); 
  41.    $this->zip->close(); 
  42.    return array ( 
  43.      true, 
  44.      "new file created: " . $this->fileInfo["fullFilePath"
  45.      ); 
  46.   } 
  47.  } 
  48.  private function addFiles() { 
  49.   foreach ($this->files as $k) { 
  50.    $this->zip->addFile($kbasename($k)); 
  51.   } 
  52.  } 
  53. $settings = array ( 
  54.   "path" => dirname(__FILE__
  55.  ); 
  56. $zipFile = new zipFile($settings); 
  57. $zipFile->files = array ( 
  58.   "./images/navoff.jpg"
  59.   "./images/navon.jpg" 
  60.  ); 
  61. list($success$error) = $zipFile->create(); 
  62. if ($success === true) { 
  63.  //success 
  64. else { 
  65.  //error because: $error 
  66. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 车致| 勃利县| 永安市| 郴州市| 敖汉旗| 五莲县| 漳平市| 东乡族自治县| 临沂市| 无极县| 垣曲县| 福安市| 宜兴市| 花莲县| 青海省| 内丘县| 饶阳县| 凤冈县| 杨浦区| 塔城市| 普洱| 万安县| 延边| 连城县| 扬中市| 射阳县| 洪泽县| 义乌市| 长春市| 赤壁市| 铜梁县| 正阳县| 城口县| 都昌县| 鄯善县| 海门市| 晋中市| 苍南县| 长治市| 萝北县| 西青区|