一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

一個(gè)PHP的ZIP壓縮類分享

功能:將文件壓縮成zip,或者rar的壓縮包。后綴名可以自定義。

使用方法:首先實(shí)例化,然后傳參。兩個(gè)參數(shù)。第一個(gè)關(guān)于你文件地址的一個(gè)Array。第二個(gè)是要你要保存的壓縮包文件的絕對地址。

使用例子:
復(fù)制代碼 代碼如下:
        $zipfiles =array("/root/pooy/test1.txt","/root/pooy/test2.txt");
        $z = new phpZip();
        //$randomstr = random(8);
        $zipfile = TEMP."/photocome_".$groupid.".zip";
        $z->Zip($zipfiles, $zipfile); //添加文件列表


php的ZIP壓縮類如下:

復(fù)制代碼 代碼如下:
<?php
#
# phpZip v1.2 by Sext (sext@neud.NET) 2002-11-18
#     (Changed: 2003-03-01)
#
# Makes zip archive
#
# Based on "Zip file creation class", uses zLib
#
#
class phpZip
{
    function Zip($dir, $zipfilename)
    {
        if (@function_exists('gzcompress'))
        {    
            $curdir = getcwd();
            if (is_array($dir))
            {
                    $filelist = $dir;
            }
            else
            {
                $filelist = $this -> GetFileList($dir);
            }

            if ((!empty($dir))&&(!is_array($dir))&&(file_exists($dir))) chdir($dir);
            else chdir($curdir);

            if (count($filelist)>0)
            {
                foreach($filelist as $filename)
                {
                    if (is_file($filename))
                    {
                        $fd = fopen ($filename, "r");
                        $content = fread ($fd, filesize ($filename));
                        fclose ($fd);

                        if (is_array($dir)) $filename = basename($filename);
                        $this -> addFile($content, $filename);
                    }
                }
                $out = $this -> file();

                chdir($curdir);
                $fp = fopen($zipfilename, "w");
                fwrite($fp, $out, strlen($out));
                fclose($fp);
            }
            return 1;
        }
        else return 0;
    }

    function GetFileList($dir)
    {
        if (file_exists($dir))
        {
            $args = func_get_args();
            $pref = $args[1];

            $dh = opendir($dir);
            while($files = readdir($dh))
            {
                if (($files!=".")&&($files!=".."))
                {
                    if (is_dir($dir.$files))
                    {
                        $curdir = getcwd();
                        chdir($dir.$files);
                        $file = array_merge($file, $this -> GetFileList("", "$pref$files/"));
                        chdir($curdir);
                    }
                    else $file[]=$pref.$files;
                }
            }
            closedir($dh);
        }
        return $file;
    }

    var $datasec      = array();
    var $ctrl_dir     = array();
    var $eof_ctrl_dir = "/x50/x4b/x05/x06/x00/x00/x00/x00";
    var $old_offset   = 0;

    /**
     * Converts an Unix timestamp to a four byte DOS date and time format (date
     * in high two bytes, time in low two bytes allowing magnitude comparison).
     *
     * @param  integer  the current Unix timestamp
     *
     * @return integer  the current date in a four byte DOS format
     *
     * @access private
     */
    function unix2DosTime($unixtime = 0) {
        $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);

        if ($timearray['year'] < 1980) {
            $timearray['year']    = 1980;
            $timearray['mon']     = 1;
            $timearray['mday']    = 1;
            $timearray['hours']   = 0;
            $timearray['minutes'] = 0;
            $timearray['seconds'] = 0;
        } // end if

        return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
                ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
    } // end of the 'unix2DosTime()' method

    /**
     * Adds "file" to archive
     *
     * @param  string   file contents
     * @param  string   name of the file in the archive (may contains the path)
     * @param  integer  the current timestamp
     *
     * @access public
     */
    function addFile($data, $name, $time = 0)
    {
        $name     = str_replace('//', '/', $name);

        $dtime    = dechex($this->unix2DosTime($time));
        $hexdtime = '/x' . $dtime[6] . $dtime[7]
                   <a >Western union point</a> .  '/x' . $dtime[4] . $dtime[5]
                  . '/x' . $dtime[2] . $dtime[3]
                  . '/x' . $dtime[0] . $dtime[1];
        eval('$hexdtime = "' . $hexdtime . '";');

        $fr   = "/x50/x4b/x03/x04";
        $fr   .= "/x14/x00";            // ver needed to extract
        $fr   .= "/x00/x00";            // gen purpose bit flag
        $fr   .= "/x08/x00";            // compression method
        $fr   .= $hexdtime;             // last mod time and date

        // "local file header" segment
        $unc_len = strlen($data);
        $crc     = crc32($data);
        $zdata   = gzcompress($data);
        $c_len   = strlen($zdata);
        $zdata   = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
        $fr      .= pack('V', $crc);             // crc32
        $fr      .= pack('V', $c_len);           // compressed filesize
        $fr      .= pack('V', $unc_len);         // uncompressed filesize
        $fr      .= pack('v', strlen($name));    // length of filename
        $fr      .= pack('v', 0);                // extra field length
        $fr      .= $name;

        // "file data" segment
        $fr .= $zdata;

        // "data descriptor" segment (optional but necessary if archive is not
        // served as file)
        $fr .= pack('V', $crc);                 // crc32
        $fr .= pack('V', $c_len);               // compressed filesize
        $fr .= pack('V', $unc_len);             // uncompressed filesize

        // add this entry to array
        $this -> datasec[] = $fr;
        $new_offset        = strlen(implode('', $this->datasec));

        // now add to central directory record
        $cdrec = "/x50/x4b/x01/x02";
        $cdrec .= "/x00/x00";                // version made by
        $cdrec .= "/x14/x00";                // version needed to extract
        $cdrec .= "/x00/x00";                // gen purpose bit flag
        $cdrec .= "/x08/x00";                // compression method
        $cdrec .= $hexdtime;                 // last mod time & date
        $cdrec .= pack('V', $crc);           // crc32
        $cdrec .= pack('V', $c_len);         // compressed filesize
        $cdrec .= pack('V', $unc_len);       // uncompressed filesize
        $cdrec .= pack('v', strlen($name) ); // length of filename
        $cdrec .= pack('v', 0 );             // extra field length
        $cdrec .= pack('v', 0 );             // file comment length
        $cdrec .= pack('v', 0 );             // disk number start
        $cdrec .= pack('v', 0 );             // internal file attributes
        $cdrec .= pack('V', 32 );            // external file attributes - 'archive' bit set

        $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
        $this -> old_offset = $new_offset;

        $cdrec .= $name;

        // optional extra field, file comment goes here
        // save to central directory
        $this -> ctrl_dir[] = $cdrec;
    } // end of the 'addFile()' method

    /**
     * Dumps out file
     *
     * @return  string  the zipped file
     *
     * @access public
     */
    function file()
    {
        $data    = implode('', $this -> datasec);
        $ctrldir = implode('', $this -> ctrl_dir);

        return
            $data .
            $ctrldir .
            $this -> eof_ctrl_dir .
            pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries "on this disk"
            pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries overall
            pack('V', strlen($ctrldir)) .           // size of central dir
            pack('V', strlen($data)) .              // offset to start of central dir
            "/x00/x00";                             // .zip file comment length
    } // end of the 'file()' method

} // end of the 'phpZip' class
?>

php技術(shù)一個(gè)PHP的ZIP壓縮類分享,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产最新精品视频 | 日本人videos18videos在线看 | 铃原爱蜜莉福利一区在线观看 | 美国一级做a爰片性色毛片 美国一区二区三区 | 黄色片网址在线观看 | 99热这里只有精品国产动漫 | 香港三级欧美国产精品 | 久久香蕉热| 成人精品亚洲人成在线 | 国产香蕉久久精品综合网 | 久久久精品一区 | 日韩中文字幕免费 | 亚洲资源在线 | 国产精品第十页 | 亚洲精品综合在线 | 在线观看亚洲 | 男女性色大片免费网站 | 五月婷婷中文字幕 | 中文字幕在线观看2023 | 九九99久久精品午夜剧场免费 | 久久伊人成人网 | 成人免费在线视频 | 国产精品久久久99 | 欧美成人免费一区在线播放 | 成人国产在线24小时播放视频 | 黄色免费网站在线观看 | 国产私拍福利精品视频网站 | 亚洲图片小说视频 | 亚洲图片欧美文学小说激情 | 黄色高清在线观看 | 午夜视频www | 国产精品亚洲小说专区 | 女人ass人体下部pic | 久久精品乱子伦免费 | 欧美wwwwww| 国产二区精品视频 | 免费国产成高清人在线视频 | 91播放| 色妞精品一区二区 | 777久久婷婷成人综合色 | a色在线|