当前位置: 首页>>代码示例>>PHP>>正文


PHP zipfile::datasec方法代码示例

本文整理汇总了PHP中zipfile::datasec方法的典型用法代码示例。如果您正苦于以下问题:PHP zipfile::datasec方法的具体用法?PHP zipfile::datasec怎么用?PHP zipfile::datasec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zipfile的用法示例。


在下文中一共展示了zipfile::datasec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: extract

 function extract($path)
 {
     self::$dir = $path;
     @mkdir(self::$dir);
     self::$datasec = array();
     // File information
     $mtime = filemtime(self::$zip);
     $size = filesize(self::$zip);
     // Read file
     $fh = fopen(self::$zip, "rb");
     $filedata = fread($fh, $size);
     fclose($fh);
     // Break into sections
     $filesecta = explode("PK", $filedata);
     // ZIP Comment
     $unpackeda = unpack('x16/v1length', $filesecta[1]);
     // Cut entries from the central directory
     $filesecta = explode("PK", $filedata);
     $filesecta = explode("PK", $filesecta[0]);
     array_shift($filesecta);
     // Removes empty entry/signature
     foreach ($filesecta as $filedata) {
         // CRC:crc, FD:file date, FT: file time, CM: compression method, GPF: general purpose flag, VN: version needed, CS: compressed size, UCS: uncompressed size, FNL: filename length
         $entrya = array();
         $entrya['error'] = "";
         $unpackeda = unpack("v1version/v1general_purpose/v1compress_method/v1file_time/v1file_date/V1crc/V1size_compressed/V1size_uncompressed/v1filename_length", $filedata);
         // Check for encryption
         $isencrypted = $unpackeda['general_purpose'] & 0x1 ? true : false;
         // Check for value block after compressed data
         if ($unpackeda['general_purpose'] & 0x8) {
             $unpackeda2 = unpack("V1crc/V1size_compressed/V1size_uncompressed", substr($filedata, -12));
             $unpackeda['crc'] = $unpackeda2['crc'];
             $unpackeda['size_compressed'] = $unpackeda2['size_uncompressed'];
             $unpackeda['size_uncompressed'] = $unpackeda2['size_uncompressed'];
             unset($unpackeda2);
         }
         $entrya['name'] = substr($filedata, 26, $unpackeda['filename_length']);
         if (substr($entrya['name'], -1) == "/") {
             continue;
         }
         if (!is_file($entrya['name'])) {
             @mkdir(self::$dir . dirname($entrya['name']));
         }
         $entrya['dir'] = dirname($entrya['name']);
         $entrya['dir'] = $entrya['dir'] == "." ? "" : $entrya['dir'];
         $entrya['name'] = basename($entrya['name']);
         $filedata = substr($filedata, 26 + $unpackeda['filename_length']);
         if (strlen($filedata) != $unpackeda['size_compressed']) {
             $entrya['error'] = "Compressed size is not equal to the value given in header.";
         }
         if ($isencrypted) {
             $entrya['error'] = "Encryption is not supported.";
         } else {
             switch ($unpackeda['compress_method']) {
                 case 0:
                     // Stored
                     // Not compressed, continue
                     break;
                 case 8:
                     // Deflated
                     $filedata = gzinflate($filedata);
                     break;
                 case 12:
                     // BZIP2
                     if (!extension_loaded("bz2")) {
                         @dl(strtolower(substr(PHP_OS, 0, 3)) == "win" ? "php_bz2.dll" : "bz2.so");
                     }
                     if (extension_loaded("bz2")) {
                         $filedata = bzdecompress($filedata);
                     } else {
                         $entrya['error'] = "Required BZIP2 Extension not available.";
                     }
                     break;
                 default:
                     $entrya['error'] = "Compression method ({$unpackeda['compress_method']}) not supported.";
             }
             if (!$entrya['error']) {
                 if ($filedata === false) {
                     $entrya['error'] = true;
                     //"Decompression failed.";
                 } elseif (strlen($filedata) != $unpackeda['size_uncompressed']) {
                     $entrya['error'] = "File size is not equal to the value given in header.";
                 } elseif (crc32($filedata) != $unpackeda['crc']) {
                     $entrya['error'] = "CRC32 checksum is not equal to the value given in header.";
                 }
             }
             $entrya['filemtime'] = mktime(($unpackeda['file_time'] & 0xf800) >> 11, ($unpackeda['file_time'] & 0x7e0) >> 5, ($unpackeda['file_time'] & 0x1f) << 1, ($unpackeda['file_date'] & 0x1e0) >> 5, $unpackeda['file_date'] & 0x1f, (($unpackeda['file_date'] & 0xfe00) >> 9) + 1980);
             $entrya['data'] = $filedata;
         }
         $files[] = $entrya;
     }
     //PrintR($files);
     //exit;
     foreach ($files as $v) {
         if ($v['error'] === true) {
             continue;
         }
         if ($v['dir']) {
             self::createDir($v['dir']);
             $file = self::$dir . $v['dir'] . '/' . $v['name'];
//.........这里部分代码省略.........
开发者ID:rigidus,项目名称:ea,代码行数:101,代码来源:zipfile.php


注:本文中的zipfile::datasec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。