⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zipimportstorage.inc.php.svn-base

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 SVN-BASE
字号:
<?php/** * $Id$ * * Manages listing and contents for documents uploaded from a zip file * * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited *  * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more * details. *  * You should have received a copy of the GNU General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. *  * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,  * California 94120-7775, or email info@knowledgetree.com. *  * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. *  * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the  * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original  * copyright notice. * Contributor( s): ______________________________________ */require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php');require_once(KT_LIB_DIR . '/import/fsimportstorage.inc.php');require_once('File/Archive.php');class KTZipImportStorage extends KTFSImportStorage {    /**     * The archive extension.     * @var string     */    var $sExtension = 'zip';    var $sZipPath = '';    var $sBasePath = '';    var $aFile = array();    var $allowed_extensions = array('tgz', 'tar', 'gz', 'zip', 'deb', 'ar');    function KTZipImportStorage($sFilesName) {        $this->aFile = $_FILES[$sFilesName];        $this->sZipPath = $this->aFile['tmp_name'];        // Check the bzip2 lib functions are available        if(function_exists('bzopen')){            $this->allowed_extensions = array_merge($this->allowed_extensions, array('bz2', 'tbz'));        }    }    function CheckFormat(){        // Get the file extension        $aFilename = explode('.', $this->aFile['name']);        $cnt = count($aFilename);        $sExtension = $aFilename[$cnt - 1];        // check if its in the list of supported extensions        if(!in_array($sExtension, $this->allowed_extensions)){            return false;        }        $this->sExtension = (!empty($sExtension)) ? $sExtension : 'zip';        // Check if the archive is a .tar.gz or .tar.bz, etc        if($cnt > 2){            if($aFilename[$cnt-2] == 'tar'){                switch($this->sExtension){                    case 'gz':                        $this->sExtension = 'tgz';                        break;                    case 'bz2':                        $this->sExtension = 'tbz';                        break;                }            }        }        return true;    }    function getFormats(){        return implode(', ', $this->allowed_extensions);    }    function init() {        $oKTConfig =& KTConfig::getSingleton();        $sBasedir = $oKTConfig->get("urls/tmpDirectory");        $sTmpPath = tempnam($sBasedir, 'archiveimportstorage');        if ($sTmpPath === false) {            return PEAR::raiseError(_kt("Could not create temporary directory for archive storage"));        }        if (!file_exists($this->sZipPath)) {            return PEAR::raiseError(_kt("Archive file given does not exist"));        }        unlink($sTmpPath);        mkdir($sTmpPath, 0700);        $this->sBasePath = $sTmpPath;        // Set environment language to output character encoding        $sOutputEncoding = $oKTConfig->get('export/encoding', 'UTF-8');        $loc = $sOutputEncoding;        putenv("LANG=$loc");        putenv("LANGUAGE=$loc");        $loc = setlocale(LC_ALL, $loc);        // File Archive doesn't unzip properly so sticking to the original unzip functionality        if($this->sExtension == 'zip'){            // ** Original zip functionality            $sUnzipCommand = KTUtil::findCommand("import/unzip", "unzip");            if (empty($sUnzipCommand)) {                return PEAR::raiseError(_kt("unzip command not found on system"));            }            $aArgs = array(                $sUnzipCommand,                "-q", "-n",                "-d", $sTmpPath,                $this->sZipPath,            );            $aRes = KTUtil::pexec($aArgs);            if ($aRes['ret'] !== 0) {                return PEAR::raiseError(_kt("Could not retrieve contents from zip storage"));            }        }else{            File_Archive::extract(                File_Archive::readArchive(                    $this->sExtension, File_Archive::readUploadedFile('file')                ),                $dst = $sTmpPath            );        }    }    function cleanup() {        if ($this->sBasePath && file_exists($this->sBasePath)) {            KTUtil::deleteDirectory($this->sBasePath);            $this->sBasePath = null;        }    }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -