php生成zip文件類實(shí)例_PHP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:php生成圖片縮略圖的方法具體如下: 這里需要用到GD2 library
這篇文章主要介紹了php生成zip文件類,實(shí)例分析了php操作zip文件的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了php生成zip文件類。分享給大家供大家參考。具體如下:
- <?php
- /*
- By: Matt Ford
- Purpose: Basic class to create zipfiles
- */
- 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獲取網(wǎng)頁(yè)里所有圖片并存入數(shù)組的方法本文實(shí)例講述了php獲取網(wǎng)頁(yè)里所有圖片并存入數(shù)組的方法。分享給大家供大家參考。具體如下: 希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)PHP教程:
- php生成圓角圖片的方法
- php按單詞截取字符串的方法
- php生成圖片縮略圖的方法
- php獲取網(wǎng)頁(yè)里所有圖片并存入數(shù)組的方法
- 經(jīng)典PHP加密解密函數(shù)Authcode()修復(fù)版代碼
- php簡(jiǎn)單實(shí)現(xiàn)快速排序的方法
- php獲取網(wǎng)頁(yè)上所有鏈接的方法
- php將HTML表格每行每列轉(zhuǎn)為數(shù)組實(shí)現(xiàn)采集表格數(shù)據(jù)的方法
- PHP常用處理靜態(tài)操作類
- php使用post數(shù)組的鍵值創(chuàng)建同名變量并賦值的方法
- php刪除指定目錄的方法
- WordPress博客程序常見(jiàn)錯(cuò)誤的解決方法
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- 談mySQL數(shù)據(jù)庫(kù)的UTF8中文網(wǎng)站全文檢索的實(shí)現(xiàn)
- php遍歷目錄方法小結(jié)
- 基于PHP Web開(kāi)發(fā)MVC框架的Smarty使用說(shuō)明
- php登錄實(shí)例代碼:用戶名與密碼驗(yàn)證器
- php安裝模式mod_php和Fastcgi的選擇與對(duì)比
- 基于PHP MySQL的聊天室設(shè)計(jì)
- PHP中浮點(diǎn)數(shù)計(jì)算比較及取整不準(zhǔn)確的解決方法
- PHP實(shí)現(xiàn)自動(dòng)對(duì)圖片進(jìn)行滾動(dòng)顯示的方法
- php刪除指定目錄的方法
- 基于php-fpm 參數(shù)的深入理解
- 相關(guān)鏈接:
- 教程說(shuō)明:
PHP教程-php生成zip文件類實(shí)例
。