<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                >[info] 壓縮包驅動 ~~~ <?php namespace base; /** * 壓縮包驅動 * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2018-12-01T21:51:08+0800 */ class ZipFolder { protected $zip; protected $root; protected $ignored_names; /** * 構造函數 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @datetime 2018-11-28T00:43:18+0800 */ public function __construct() { if(class_exists('ZipArchive')) { $this->zip = new \ZipArchive(); } else { throw new \Exception('當前PHP環境無Zip擴展'); } } /** * 解壓zip文件到指定文件夾 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2018-06-29 * @desc description * @param [string] $zipfile [壓縮文件路徑] * @param [string] $path [壓縮包解壓到的目標路徑] * @return [boolean] [true | false] */ public function Unzip($zipfile, $path) { if($this->zip->open($zipfile) === true) { $file_tmp = @fopen($zipfile, "rb"); // 只讀15字節 各個不同文件類型,頭信息不一樣。 $bin = fread($file_tmp, 15); fclose($file_tmp); // 只針對zip的壓縮包進行處理 if(true === $this->GetTypeList($bin)) { $result = $this->zip->extractTo($path); $this->zip->close(); return $result; } } return false; } /** * 創建壓縮文件 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2018-06-29 * @desc description * @param [string] $zipfile [將要生成的壓縮文件路徑] * @param [string] $folder [將要被壓縮的文件夾路徑] * @param [string] $ignored [要忽略的文件列表] * @return [boolean] [true | false] */ public function Zip($zipfile, $folder, $ignored = null) { $this->ignored_names = is_array($ignored) ? $ignored : ($ignored ? array($ignored) : array()); if($this->zip->open($zipfile, \ZipArchive::CREATE) !== true) { throw new \Exception("cannot open <$zipfile>\n"); } $folder = substr($folder, -1) == '/' ? substr($folder, 0, strlen($folder)-1) : $folder; if(strstr($folder, '/')) { $this->root = substr($folder, 0, strrpos($folder, '/')+1); $folder = substr($folder, strrpos($folder, '/')+1); } $this->CreateZip($folder); return $this->zip->close(); } /** * 遞歸添加文件到壓縮包 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2018-06-29 * @desc description * @param [string] $folder [添加到壓縮包的文件夾路徑] * @param [string] $parent [添加到壓縮包的文件夾上級路徑] */ private function CreateZip($folder, $parent = null) { $full_path = $this->root . $parent . $folder; $zip_path = $parent . $folder; $this->zip->addEmptyDir($zip_path); $dir = new \DirectoryIterator($full_path); foreach($dir as $file) { if(!$file->isDot()) { $filename = $file->getFilename(); if(!in_array($filename, $this->ignored_names)) { if($file->isDir()) { $this->CreateZip($filename, $zip_path.'/'); } else { $this->zip->addFile($full_path.'/'.$filename, $zip_path.'/'.$filename); } } } } } /** * 讀取壓縮包文件與目錄列表 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2018-06-29 * @desc description * @param [string] $zipfile [壓縮包文件] * @return [array] [文件與目錄列表] */ public function FileList($zipfile) { $file_dir_list = array(); $file_list = array(); if($this->zip->open($zipfile) == true) { for ($i = 0; $i < $this->zip->numFiles; $i++) { $numfiles = $this->zip->getNameIndex($i); if(preg_match('/\/$/i', $numfiles)) { $file_dir_list[] = $numfiles; } else { $file_list[] = $numfiles; } } } return array('files'=>$file_list, 'dirs'=>$file_dir_list); } /** * 得到文件頭與文件類型映射表 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2018-06-29 * @desc description * @param [string] $bin [文件的二進制前一段字符] * @return [boolean] [true | false] */ private function GetTypeList($bin) { $array = array( array("504B0304", "zip") ); foreach($array as $v) { $blen = strlen(pack("H*", $v[0])); //得到文件頭標記字節數 $tbin = substr($bin, 0, intval($blen)); ///需要比較文件頭長度 if(strtolower($v[0]) == strtolower(array_shift(unpack("H*", $tbin)))) { return true; } } return false; } } ?> ~~~ * **例子:** ~~~ // 生成壓縮包 $app_data_zip = 'E:/xx.zip'; $app_data_dir = 'E:/xx'; $zip = new \base\ZipFolder(); if(!$zip->zip($app_data_zip, $app_data_dir)) { return '生成失敗'; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看