+ -
当前位置:首页 → 问答吧 → [修改]共享一下我今天修改的解压zip包的类

[修改]共享一下我今天修改的解压zip包的类

时间:2007-04-13

来源:互联网

复制PHP内容到剪贴板
PHP代码:
function ExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options){
        $v_result=1;
        if (($v_result = $this->ReadFileHeader($v_header)) != 1){
            return $v_result;
        }
        if ($this->CheckFileHeaders($v_header, $p_entry) != 1) {
            
        }
        if ($p_remove_all_path == true) {
            if (($p_entry['external']&0x00000010)==0x00000010) {
                $p_entry['status'] = "filtered";
                return $v_result;
            }
            $p_entry['filename'] = basename($p_entry['filename']);
        }else if($p_remove_path != ""){
            if ($this->PathInclusion($p_remove_path, $p_entry['filename']) == 2){
                $p_entry['status'] = "filtered";
                return $v_result;
            }
            $p_remove_path_size = strlen($p_remove_path);
            if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path){
                $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
            }
        }
        if ($p_path != '') {
            $p_entry['filename'] = $p_path."/".$p_entry['filename'];
        }
        if (isset($p_options[77019])) {
            $v_inclusion
            = $this->PathInclusion($p_options[77019],
            $p_entry['filename']);
            if ($v_inclusion == 0) {
                return ;
            }
        }
        if (isset($p_options[78001])) {
            $v_local_header = array();
            $this->ConvertHeader2FileInfo($p_entry, $v_local_header);
            eval('$v_result = '.$p_options[78001].'(78001, $v_local_header);');
            if ($v_result == 0) {
                $p_entry['status'] = "skipped";
                $v_result = 1;
            }
            if ($v_result == 2) {
                $p_entry['status'] = "aborted";
                $v_result = 2;
            }
            $p_entry['filename'] = $v_local_header['filename'];
        }
        if ($p_entry['status'] == 'ok') {
            if (file_exists($p_entry['filename'])){
                if (is_dir($p_entry['filename'])){
                    $p_entry['status'] = "already_a_directory";
                    if (   (isset($p_options[77017]))
                    && ($p_options[77017]===true)) {
                        return ;
                    }
                }else if (!is_writeable($p_entry['filename'])){
                    $p_entry['status'] = "write_protected";
                    if (   (isset($p_options[77017]))
                    && ($p_options[77017]===true)) {
                        return ;
                    }
                }else if (filemtime($p_entry['filename']) > $p_entry['mtime']){
                    if ((isset($p_options[77016]))
                    && ($p_options[77016]===true)) {
                    }else{
                        $p_entry['status'] = "newer_exist";
                        if ((isset($p_options[77017]))
                        && ($p_options[77017]===true)) {
                            return ;
                        }
                    }
                }else {
                }
            }else{
                if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
                $v_dir_to_check = $p_entry['filename'];
                else if (!strstr($p_entry['filename'], "/"))
                $v_dir_to_check = "";
                else
                $v_dir_to_check = dirname($p_entry['filename']);
                if (($v_result = $this->DirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
                    $p_entry['status'] = "path_creation_fail";
                    $v_result = 1;
                }
            }
        }
        if ($p_entry['status'] == 'ok') {
            if (!(($p_entry['external']&0x00000010)==0x00000010)){
                if ($p_entry['compression'] == 0) {
                    if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
                    {
                        $p_entry['status'] = "write_error";
                        return $v_result;
                    }
                    $v_size = $p_entry['compressed_size'];
                    while ($v_size != 0){
                        $v_read_size = ($v_size < BLOCK_SIZE ? $v_size : BLOCK_SIZE);
                        $v_buffer = @fread($this->zip_fd, $v_read_size);
                        @fwrite($v_dest_file, $v_buffer, $v_read_size);
                        $v_size -= $v_read_size;
                    }
                    fclose($v_dest_file);
                    touch($p_entry['filename'], $p_entry['mtime']);
                }else{
                    if (($p_entry['flag'] & 1) == 1) {
                    }
                    else {
                        $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
                    }
                    $v_file_content = @gzinflate($v_buffer);
                    unset($v_buffer);
                    if ($v_file_content === FALSE) {
                        $p_entry['status'] = "error";
                        return $v_result;
                    }
                    if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
                        $p_entry['status'] = "write_error";
                        return $v_result;
                    }
                    @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
                    unset($v_file_content);
                    @fclose($v_dest_file);
                    @touch($p_entry['filename'], $p_entry['mtime']);
                }
                if (isset($p_options[77005])) {
                    @chmod($p_entry['filename'], $p_options[77005]);
                }
            }
        }
        if ($p_entry['status'] == "aborted") {
            $p_entry['status'] = "skipped";
        }elseif (isset($p_options[78002])) {
            $v_local_header = array();
            $this->ConvertHeader2FileInfo($p_entry, $v_local_header);
            eval('$v_result = '.$p_options[78002].'(78002, $v_local_header);');
            if ($v_result == 2) {
                $v_result = 2;
            }
        }
        return $v_result;
    }
}//END class



//exam

$file="./text.zip";
$target= "./TEXT3";
$task = new UnpackZip($file);
$task->ExtractZip($target);

[ 本帖最后由 muqiao 于 2007-4-12 17:19 编辑 ]

作者: muqiao   发布时间: 2007-04-12

其实还可以简化好多

外国人真是的  长篇大论!!!!  乱七八糟

作者: muqiao   发布时间: 2007-04-12