Browse Source

移除zip

tags/6.2.0
tianya 1 year ago
parent
commit
854fa36cf3
9 changed files with 4 additions and 698 deletions
  1. +0
    -49
      src/admin/album_add.php
  2. +0
    -43
      src/admin/album_edit.php
  3. +0
    -26
      src/admin/module_upload.php
  4. +0
    -28
      src/admin/templets/album_add.htm
  5. +0
    -28
      src/admin/templets/album_edit.htm
  6. +2
    -0
      src/install/update.txt
  7. BIN
      src/static/web/img/typeid2bg.gif
  8. +2
    -18
      src/system/libraries/splitword.class.php
  9. +0
    -506
      src/system/libraries/zip.class.php

+ 0
- 49
src/admin/album_add.php View File

@@ -121,59 +121,10 @@ else if ($dopost == 'save') {
处理从ZIP中解压的图片
---------------------*/
if ($formzip == 1) {
include_once(DEDEINC."/libraries/zip.class.php");
include_once(DEDEADMIN."/file_class.php");
$zipfile = $cfg_basedir.str_replace($cfg_mainsite, '', $zipfile);
$tmpzipdir = DEDEDATA.'/ziptmp/'.cn_substr(md5(ExecTime()), 16);
$ntime = time();
if (file_exists($zipfile)) {
@mkdir($tmpzipdir, $GLOBALS['cfg_dir_purview']);
@chmod($tmpzipdir, $GLOBALS['cfg_dir_purview']);
$z = new zip();
$z->ExtractAll($zipfile, $tmpzipdir);
$fm = new FileManagement();
$imgs = array();
$fm->GetMatchFiles($tmpzipdir, "jpg|png|gif", $imgs);
$i = 0;
foreach ($imgs as $imgold) {
$i++;
$savepath = $cfg_image_dir."/".MyDate("Y-m", $ntime);
CreateDir($savepath);
$iurl = $savepath."/".MyDate("d", $ntime).dd2char(MyDate("His", $ntime).'-'.$adminid."-{$i}".mt_rand(1000, 9999));
$iurl = $iurl.substr($imgold, -4, 4);
$imgfile = $cfg_basedir.$iurl;
copy($imgold, $imgfile);
unlink($imgold);
if (is_file($imgfile)) {
$litpicname = $pagestyle > 2 ? GetImageMapDD($iurl, $cfg_ddimg_width) : $iurl;
//指定了提取第一张为缩略图的情况强制使用第一张缩略图
if ($i == '1') {
if (!$hasone && $ddisfirst == 1 && $litpic == '' && empty($litpicname)) {
$litpicname = GetImageMapDD($iurl, $cfg_ddimg_width);
}
}
$info = '';
$imginfos = GetImageSize($imgfile, $info);
$imgurls .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
//把图片信息保存到媒体文档管理文档中
$inquery = "INSERT INTO `#@__uploads` (title,url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ('{$title}','{$iurl}','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".$ntime."','$adminid');";
$dsql->ExecuteNoneQuery($inquery);
$fid = $dsql->GetLastID();
AddMyAddon($fid, $iurl);
WaterImg($imgfile, 'up');
if (!$hasone && $ddisfirst == 1 && $litpic == '') {
if (empty($litpicname)) {
$litpicname = $iurl;
$litpicname = GetImageMapDD($iurl, $cfg_ddimg_width);
}
$litpic = $litpicname;
$hasone = TRUE;
}
}
}
if ($delzip == 1) unlink($zipfile);
$fm->RmDirFiles($tmpzipdir);
}
}
if ($albums !== "") {
$albumsArr = json_decode(stripslashes($albums), true);


+ 0
- 43
src/admin/album_edit.php View File

@@ -196,53 +196,10 @@ else if ($dopost == 'save') {
从ZIP文件中获取新图片
---------------------*/
if ($formzip == 1) {
include_once(DEDEINC."/libraries/zip.class.php");
include_once(DEDEADMIN."/file_class.php");
$zipfile = $cfg_basedir.str_replace($cfg_mainsite, '', $zipfile);
$tmpzipdir = DEDEDATA.'/ziptmp/'.cn_substr(md5(ExecTime()), 16);
$ntime = time();
if (file_exists($zipfile)) {
@mkdir($tmpzipdir, $GLOBALS['cfg_dir_purview']);
@chmod($tmpzipdir, $GLOBALS['cfg_dir_purview']);
$z = new zip();
$z->ExtractAll($zipfile, $tmpzipdir);
$fm = new FileManagement();
$imgs = array();
$fm->GetMatchFiles($tmpzipdir, "jpg|png|gif", $imgs);
$i = 0;
foreach ($imgs as $imgold) {
$i++;
$savepath = $cfg_image_dir."/".MyDate("Y-m", $ntime);
CreateDir($savepath);
$iurl = $savepath."/".MyDate("d", $ntime).dd2char(MyDate("His", $ntime).'-'.$adminid."-{$i}".mt_rand(1000, 9999));
$iurl = $iurl.substr($imgold, -4, 4);
$imgfile = $cfg_basedir.$iurl;
copy($imgold, $imgfile);
unlink($imgold);
if (is_file($imgfile)) {
$litpicname = $pagestyle > 2 ? GetImageMapDD($iurl, $cfg_ddimg_width) : $iurl;
$info = '';
$imginfos = GetImageSize($imgfile, $info);
$imgurls .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
//把图片信息保存到媒体文档管理文档中
$inquery = "INSERT INTO `#@__uploads` (title,url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ('{$title}','{$iurl}','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".$ntime."','$adminid');";
$dsql->ExecuteNoneQuery($inquery);
if (
!$hasone && $ddisfirst == 1
&& $litpic == "" && !empty($litpicname)
) {
if (file_exists($cfg_basedir.$litpicname)) {
$litpic = $litpicname;
$hasone = true;
}
}
}
}
if ($delzip == 1) {
unlink($zipfile);
}
$fm->RmDirFiles($tmpzipdir);
}
}
if ($albums !== "") {
$albumsArr = json_decode(stripslashes($albums), true);


+ 0
- 26
src/admin/module_upload.php View File

@@ -25,31 +25,6 @@ if ($action == 'upload') {
include_once(DEDEINC."/libraries/zip.class.php");
$tmpfilename = $mdir.'/'.ExecTime().mt_rand(10000, 50000).'.tmp';
move_uploaded_file($upfile, $tmpfilename) or die("把上传的文件移动到{$tmpfilename}时失败,请检查{$mdir}目录是否有写入权限");
//ZIP格式的文件
if ($filetype == 1) {
$z = new zip();
$files = $z->get_List($tmpfilename);
$dedefileindex = -1;
//为了节省资源,系统仅以.xml作为扩展名识别ZIP包里了模块格式文件
if (is_array($files)) {
for ($i = 0; $i < count($files); $i++) {
if (preg_match("#\.xml#i", $files[$i]['filename'])) {
$dedefile = $files[$i]['filename'];
$dedefileindex = $i;
break;
}
}
}
if ($dedefileindex == -1) {
unlink($tmpfilename);
ShowMsg("对不起,您上传的压缩包中不存在模块文件<br><a href='javascript:history.go(-1);'>重新上传</a>", "javascript:;");
exit();
}
$ziptmp = $mdir.'/ziptmp';
$z->Extract($tmpfilename, $ziptmp, $dedefileindex);
unlink($tmpfilename);
$tmpfilename = $mdir."/ziptmp/".$dedefile;
}
$dm = new DedeModule($mdir);
$infos = $dm->GetModuleInfo($tmpfilename, 'file');
if (empty($infos['hash'])) {
@@ -87,7 +62,6 @@ if ($action == 'upload') {
<td width='260'>文件格式:</td>
<td>
<label><input type='radio' name='filetype' value='0' checked='checked'> 正常的模块包</label>
<label><input type='radio' name='filetype' value='1'> 经过zip压缩的模块包</label>
</td>
</tr>
<tr>


+ 0
- 28
src/admin/templets/album_add.htm View File

@@ -274,34 +274,6 @@
</table>
</td>
</tr>
<tr>
<td class="biz-td">
<table cellspacing="0" cellpadding="0">
<tr>
<td width="90">上传方式:</td>
<td>
<input type="hidden" name="isrm" id="isrm" value="1">
<label><input type="checkbox" name="byhand" id="byhand" value="1" disabled="ture" checked> 手工上传</label>
<label><input type="checkbox" name="formzip" id="formzip" value="1" onClick="showZipField(this,'zipff','htmlfield')"> 从ZIP压缩包中解压图片</label>
</td>
</tr>
</table>
</td>
</tr>
<tr id="zipff" style="display:none">
<td class="biz-td">
<table cellspacing="0" cellpadding="0" height="100">
<tr>
<td width="90">压缩包文件:</td>
<td>
<input type="text" name="zipfile" id="zipfile" class="biz-input-md">
<button name="addon_bt" type="button" onClick="SelectSoft('form1.zipfile')" class="btn btn-success btn-sm">浏览</button>
<label><input type="checkbox" name="delzip" id="delzip" value="1" checked="checked"> 处理后删除压缩文件</label>
</td>
</tr>
</table>
</td>
</tr>
<tr id="htmlfield" style="display:none">
<td class="biz-td">
<table cellspacing="0" cellpadding="0">


+ 0
- 28
src/admin/templets/album_edit.htm View File

@@ -275,34 +275,6 @@
</table>
</td>
</tr>
<tr>
<td class="biz-td">
<table cellspacing="0" cellpadding="0">
<tr>
<td width="90">上传方式:</td>
<td>
<input type="hidden" name="isrm" id="isrm" value="1">
<label><input type="checkbox" name="byhand" id="byhand" value="1" disabled="ture" checked> 手工上传</label>
<label><input type="checkbox" name="formzip" id="formzip" value="1" onClick="showZipField(this,'zipff','htmlfield')"> 从ZIP压缩包中解压图片</label>
</td>
</tr>
</table>
</td>
</tr>
<tr id="zipff" style="display:none">
<td class="biz-td">
<table cellspacing="0" cellpadding="0" height="100">
<tr>
<td width="90">压缩包文件:</td>
<td>
<input type="text" name="zipfile" id="zipfile" class="biz-input-md">
<button type="button" name="addon_bt" class="btn btn-success btn-sm" onClick="SelectSoft('form1.zipfile')">浏览</button>
<label><input type="checkbox" name="delzip" id="delzip" value="1" checked="checked"> 处理后删除压缩文件</label>
</td>
</tr>
</table>
</td>
</tr>
<tr id="htmlfield" style="display:none">
<td class="biz-td">
<table cellspacing="0" cellpadding="0">


+ 2
- 0
src/install/update.txt View File

@@ -102,3 +102,5 @@ DELETE FROM `#@__sysconfig` WHERE `#@__sysconfig`.`varname` = 'cfg_disable_funs'
DELETE FROM `#@__sysconfig` WHERE `#@__sysconfig`.`varname` = 'cfg_disable_tags';
DELETE FROM `#@__sysconfig` WHERE `#@__sysconfig`.`varname` = 'cfg_vdcode_member';

-- 6.2.0
ALTER TABLE `#@__arctype` CHANGE COLUMN `iscross` `cross` tinyint(1) NOT NULL DEFAULT 0 AFTER `ishidden`;

BIN
src/static/web/img/typeid2bg.gif View File

Before After
Width: 201  |  Height: 15  |  Size: 1.9KB

+ 2
- 18
src/system/libraries/splitword.class.php View File

@@ -58,7 +58,7 @@ class SplitWord
//粗分后的数组(通常是截取句子等用途)
var $simpleResult = array();
//最终结果(用空格分开的词汇列表)
var $finallyResult = '';
var $finallyResult = array();
//是否已经载入词典
var $isLoadDic = FALSE;
//系统识别或合并的新词
@@ -126,7 +126,7 @@ class SplitWord
$this->mainDicHand = fopen($this->mainDicFile, 'r');
}
$p = 0;
$keynum = $this->_get_index( $key );
$keynum = (int)$this->_get_index( $key );
if ( isset($this->mainDicInfos[ $keynum ]) )
{
$data = $this->mainDicInfos[ $keynum ];
@@ -217,8 +217,6 @@ class SplitWord
//加载主词典(只打开)
if ($this->isUnpacked){
$this->mainDicHand = fopen($dicWords, 'r');
} else {
$this->InportDict($this->mainDicFileZip);
}
//载入副词典
$hw = '';
@@ -1032,18 +1030,4 @@ class SplitWord
fclose( $fp );
return TRUE;
}
function InportDict( $targetfile )
{
if (!ini_set('memory_limit', '128M'))
exit('设置内存错误,请到官网下载解压版的base_dic_full.dic!');
require_once(DEDEINC.'/libraries/zip.class.php');
$zip = new zip();
//echo $targetfile;
$unpackagefile = array_keys($zip->Extract($targetfile,DEDEINC.'/data/'));
//exit();
$this->MakeDict(DEDEINC.'/data/'.$unpackagefile[0]);
unlink(DEDEINC.'/data/'.$unpackagefile[0]);
return true;
}
}
?>

+ 0
- 506
src/system/libraries/zip.class.php View File

@@ -1,506 +0,0 @@
<?php
if (!defined('DEDEINC')) exit('dedebiz');
/**
* Zip压缩类
*
* @version $id:zip.class.php 15:21 2010年7月5日 tianya $
* @package DedeBIZ.Libraries
* @copyright Copyright (c) 2022 DedeBIZ.COM
* @license https://www.dedebiz.com/license
* @link https://www.dedebiz.com
*/
class zip
{
var $datasec, $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
var $dirs = array(".");
/**
* 获取zip文件中的文件列表
*
* @access public
* @param string $zip_name zip文件名
* @return array
*/
function get_List($zip_name)
{
$ret = '';
$zip = @fopen($zip_name, 'rb');
if (!$zip) {
return (0);
}
$centd = $this->ReadCentralDir($zip, $zip_name);
@rewind($zip);
@fseek($zip, $centd['offset']);
for ($i = 0; $i < $centd['entries']; $i++) {
$header = $this->ReadCentralFileHeaders($zip);
$header['index'] = $i;
$info['filename'] = $header['filename'];
$info['stored_filename'] = $header['stored_filename'];
$info['size'] = $header['size'];
$info['compressed_size'] = $header['compressed_size'];
$info['crc'] = strtoupper(dechex($header['crc']));
$info['mtime'] = $header['mtime'];
$info['comment'] = $header['comment'];
$info['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0;
$info['index'] = $header['index'];
$info['status'] = $header['status'];
$ret[] = $info;
unset($header);
}
return $ret;
}
/**
* 增加文件到压缩文件
*
* @access public
* @param string $files 需要增加的文件列表,可以是字符串也可以是数组
* @param string $compact 压缩文件名称
* @return array 压缩文件信息
*/
function Add($files, $compact)
{
if (!is_array($files[0])) {
$files = array($files);
}
for ($i = 0; $files[$i]; $i++) {
$fn = $files[$i];
if (!in_Array(dirname($fn[0]), $this->dirs)) {
$this->add_Dir(dirname($fn[0]));
}
if (basename($fn[0])) {
$ret[basename($fn[0])] = $this->add_File($fn[1], $fn[0], $compact);
}
}
return $ret;
}
/**
* 获取文件,获取后可以让其进行下载
*
* @access public
* @return void
*/
function get_file()
{
$data = implode('', $this->datasec);
$ctrldir = implode('', $this->ctrl_dir);
return $data.$ctrldir.$this->eof_ctrl_dir .
pack('v', sizeof($this->ctrl_dir)).pack('v', sizeof($this->ctrl_dir)) .
pack('V', strlen($ctrldir)).pack('V', strlen($data))."\x00\x00";
}
/**
* 增加文件目录
*
* @access public
* @param string $name 目录名称
* @return void
*/
function add_dir($name)
{
$name = str_replace("\\", "/", $name);
$fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$fr .= pack("V", 0).pack("V", 0).pack("V", 0).pack("v", strlen($name));
$fr .= pack("v", 0).$name.pack("V", 0).pack("V", 0).pack("V", 0);
$this->datasec[] = $fr;
$new_offset = strlen(implode("", $this->datasec));
$cdrec = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$cdrec .= pack("V", 0).pack("V", 0).pack("V", 0).pack("v", strlen($name));
$cdrec .= pack("v", 0).pack("v", 0).pack("v", 0).pack("v", 0);
$ext = "\xff\xff\xff\xff";
$cdrec .= pack("V", 16).pack("V", $this->old_offset).$name;
$this->ctrl_dir[] = $cdrec;
$this->old_offset = $new_offset;
$this->dirs[] = $name;
}
/**
* 编译指定的文件为zip文件(filename可以为文件数组array、目录dir或单个文件file)
*
* @access public
* @param string $filename 文件名称
* @param string $tozipfilename 压缩文件名称
* @param string $ftype 压缩类型
* @return int 影响文件数
*/
function CompileZipFile($filename, $tozipfilename, $ftype = 'dir')
{
if (@function_exists('gzcompress')) {
if ($ftype == 'dir') {
$filelist = $this->ListDirFiles($filename);
} else if ($ftype == 'file') {
$filelist[] = $filename;
} else {
$filelist = $filename;
}
$i = 0;
if (count($filelist) > 0) {
foreach ($filelist as $filename) {
if (is_file($filename)) {
$i++;
$fd = fopen($filename, "r");
if (filesize($filename) > 0) {
$content = fread($fd, filesize($filename));
} else {
$content = ' ';
}
fclose($fd);
//if (is_array($dir)) $filename = basename($filename);
$this->add_File($content, $filename);
}
}
$out = $this->get_file();
$fp = fopen($tozipfilename, "w");
fwrite($fp, $out, strlen($out));
fclose($fp);
}
return $i;
} else {
return 0;
}
}
/**
* 读取某文件夹的所有文件
*
* @access public
* @param string $dirname 目录名称
* @return mix 如果失败则返回false
*/
function ListDirFiles($dirname)
{
$files = array();
if (is_dir($dirname)) {
$fh = opendir($dirname);
while (($file = readdir($fh)) !== false) {
if (strcmp($file, '.') == 0 || strcmp($file, '..') == 0) {
continue;
}
$filepath = $dirname.'/'.$file;
if (is_dir($filepath)) {
$files = array_merge($files, $this->ListDirFiles($filepath));
} else {
array_push($files, $filepath);
}
}
closedir($fh);
} else {
$files = false;
}
return $files;
}
/**
* 增加文件
*
* @access public
* @param string $data 数据
* @param string $name 名称
* @param string $compact 压缩
* @return string
*/
function add_File($data, $name, $compact = 1)
{
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->DosTime());
$hexdtime = '\x'.$dtime[6].$dtime[7].'\x'.$dtime[4].$dtime[5]
.'\x'.$dtime[2].$dtime[3].'\x'.$dtime[0].$dtime[1];
eval('$hexdtime = "'.$hexdtime.'";');
if ($compact)
$fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00".$hexdtime;
else {
$fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00".$hexdtime;
}
$unc_len = strlen($data);
$crc = crc32($data);
if ($compact) {
$zdata = gzcompress($data);
$c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
} else {
$zdata = $data;
}
$c_len = strlen($zdata);
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata;
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$this->datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
if ($compact) {
$cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00";
} else {
$cdrec = "\x50\x4b\x01\x02\x14\x00\x0a\x00\x00\x00\x00\x00";
}
$cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$cdrec .= pack('v', strlen($name)).pack('v', 0).pack('v', 0);
$cdrec .= pack('v', 0).pack('v', 0).pack('V', 32);
$cdrec .= pack('V', $this->old_offset);
$this->old_offset = $new_offset;
$cdrec .= $name;
$this->ctrl_dir[] = $cdrec;
return true;
}
/**
* 返回时间
*
* @access public
* @return int
*/
function DosTime()
{
$timearray = getdate();
if ($timearray['year'] < 1980) {
$timearray['year'] = 1980;
$timearray['mon'] = 1;
$timearray['mday'] = 1;
$timearray['hours'] = 0;
$timearray['minutes'] = 0;
$timearray['seconds'] = 0;
}
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) |
($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
}
/**
* 解压整个压缩包
* 直接用 Extract 会有路径问题,本函数先从列表中获得文件信息并创建好所有目录然后才运行 Extract
*
* @access public
* @param string $zn zip文件名称
* @param string $to 解压到的目录地址
* @return string
*/
function ExtractAll($zn, $to)
{
if (substr($to, -1) != "/") {
$to .= "/";
}
$files = $this->get_List($zn);
$cn = count($files);
if (is_array($files)) {
for ($i = 0; $i < $cn; $i++) {
if ($files[$i]['folder'] == 1) {
@mkdir($to.$files[$i]['filename'], $GLOBALS['cfg_dir_purview']);
@chmod($to.$files[$i]['filename'], $GLOBALS['cfg_dir_purview']);
}
}
}
$this->Extract($zn, $to);
}
/**
* 解压单个文件
*
* @access public
* @param string $zn zip文件名称
* @param string $to 解压到的目录地址
* @return string
*/
function Extract($zn, $to, $index = array(-1))
{
$ok = 0;
$zip = @fopen($zn, 'rb');
if (!$zip) {
return (-1);
}
$cdir = $this->ReadCentralDir($zip, $zn);
$pos_entry = $cdir['offset'];
if (!is_array($index)) {
$index = array($index);
}
for ($i = 0; isset($index[$i]); $i++) {
if (intval($index[$i]) != $index[$i] || $index[$i] > $cdir['entries']) {
return (-1);
}
}
for ($i = 0; $i < $cdir['entries']; $i++) {
@fseek($zip, $pos_entry);
$header = $this->ReadCentralFileHeaders($zip);
$header['index'] = $i;
$pos_entry = ftell($zip);
@rewind($zip);
fseek($zip, $header['offset']);
if (in_array("-1", $index) || in_array($i, $index)) {
$stat[$header['filename']] = $this->ExtractFile($header, $to, $zip);
}
}
fclose($zip);
return $stat;
}
function ReadFileHeader($zip)
{
$binary_data = fread($zip, 30);
$data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);
$header['filename'] = fread($zip, $data['filename_len']);
if ($data['extra_len'] != 0) {
$header['extra'] = fread($zip, $data['extra_len']);
} else {
$header['extra'] = '';
}
$header['compression'] = $data['compression'];
$header['size'] = $data['size'];
$header['compressed_size'] = $data['compressed_size'];
$header['crc'] = $data['crc'];
$header['flag'] = $data['flag'];
$header['mdate'] = $data['mdate'];
$header['mtime'] = $data['mtime'];
if ($header['mdate'] && $header['mtime']) {
$hour = ($header['mtime'] & 0xF800) >> 11;
$minute = ($header['mtime'] & 0x07E0) >> 5;
$seconde = ($header['mtime'] & 0x001F) * 2;
$year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
$month = ($header['mdate'] & 0x01E0) >> 5;
$day = $header['mdate'] & 0x001F;
$header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
} else {
$header['mtime'] = time();
}
$header['stored_filename'] = $header['filename'];
$header['status'] = "ok";
return $header;
}
function ReadCentralFileHeaders($zip)
{
$binary_data = fread($zip, 46);
$header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);
if ($header['filename_len'] != 0) {
$header['filename'] = fread($zip, $header['filename_len']);
} else {
$header['filename'] = '';
}
if ($header['extra_len'] != 0) {
$header['extra'] = fread($zip, $header['extra_len']);
} else {
$header['extra'] = '';
}
if ($header['comment_len'] != 0) {
$header['comment'] = fread($zip, $header['comment_len']);
} else {
$header['comment'] = '';
}
if ($header['mdate'] && $header['mtime']) {
$hour = ($header['mtime'] & 0xF800) >> 11;
$minute = ($header['mtime'] & 0x07E0) >> 5;
$seconde = ($header['mtime'] & 0x001F) * 2;
$year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
$month = ($header['mdate'] & 0x01E0) >> 5;
$day = $header['mdate'] & 0x001F;
$header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
} else {
$header['mtime'] = time();
}
$header['stored_filename'] = $header['filename'];
$header['status'] = 'ok';
if (substr($header['filename'], -1) == '/') {
$header['external'] = 0x41FF0010;
}
return $header;
}
function ReadCentralDir($zip, $zip_name)
{
$size = filesize($zip_name);
if ($size < 277) {
$maximum_size = $size;
} else {
$maximum_size = 277;
}
@fseek($zip, $size - $maximum_size);
$pos = ftell($zip);
$bytes = 0x00000000;
while ($pos < $size) {
$byte = @fread($zip, 1);
$bytes = ($bytes << 8) | Ord($byte);
if ($bytes == 0x504b0506) {
$pos++;
break;
}
$pos++;
}
$data = @unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', fread($zip, 18));
if ($data['comment_size'] != 0) {
$centd['comment'] = fread($zip, $data['comment_size']);
} else {
$centd['comment'] = '';
$centd['entries'] = $data['entries'];
}
$centd['disk_entries'] = $data['disk_entries'];
$centd['offset'] = $data['offset'];
$centd['disk_start'] = $data['disk_start'];
$centd['size'] = $data['size'];
$centd['disk'] = $data['disk'];
return $centd;
}
function ExtractFile($header, $to, $zip)
{
$header = $this->readfileheader($zip);
$header['external'] = (!isset($header['external']) ? 0 : $header['external']);
if (substr($to, -1) != "/") {
$to .= "/";
}
if (!@is_dir($to)) {
@mkdir($to, $GLOBALS['cfg_dir_purview']);
}
if (!($header['external'] == 0x41FF0010) && !($header['external'] == 16)) {
if ($header['compression'] == 0) {
$fp = @fopen($to.$header['filename'], 'wb');
if (!$fp) {
return (-1);
}
$size = $header['compressed_size'];
while ($size != 0) {
$read_size = ($size < 2048 ? $size : 2048);
$buffer = fread($zip, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
fclose($fp);
touch($to.$header['filename'], $header['mtime']);
} else {
$fp = @fopen($to.$header['filename'].'.gz', 'wb');
if (!$fp) {
return (-1);
}
$binary_data = pack(
'va1a1Va1a1',
0x8b1f,
Chr($header['compression']),
Chr(0x00),
time(),
Chr(0x00),
Chr(3)
);
fwrite($fp, $binary_data, 10);
$size = $header['compressed_size'];
while ($size != 0) {
$read_size = ($size < 1024 ? $size : 1024);
$buffer = fread($zip, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
$binary_data = pack('VV', $header['crc'], $header['size']);
fwrite($fp, $binary_data, 8);
fclose($fp);
$gzp = @gzopen($to.$header['filename'].'.gz', 'rb') or die("Cette archive est compress");
if (!$gzp) {
return (-2);
}
$fp = @fopen($to.$header['filename'], 'wb');
if (!$fp) {
return (-1);
}
$size = $header['size'];
while ($size != 0) {
$read_size = ($size < 2048 ? $size : 2048);
$buffer = gzread($gzp, $read_size);
$binary_data = pack('a'.$read_size, $buffer);
@fwrite($fp, $binary_data, $read_size);
$size -= $read_size;
}
fclose($fp);
gzclose($gzp);
touch($to.$header['filename'], $header['mtime']);
@unlink($to.$header['filename'].'.gz');
}
}
return true;
}
}
?>

Loading…
Cancel
Save