好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>后端语言>PHP
<tfoot draggable='sEl'></tfoot>

phpzip函数 phpize

很多站长朋友们都不太清楚phpzip函数,今天小编就来给大家整理phpzip函数,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 php怎样实现对zip文件的加密和解密 2、 php如何压缩一个文件夹里面所有的文件到zip文件里面? 3、 怎样用php压缩解压rar,zip文件? 4、 php 数组追加 5、 编译PHP提示zip错误,请问怎么解决 6、 为什么php创建zip文件不管用 php怎样实现对zip文件的加密和解密

使用PHPZip类就可以解决的。以下是网上找到的例子。

        $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

# 

# 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 = "x50x4bx05x06x00x00x00x00";

    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]

                  . 'x' . $dtime[4] . $dtime[5]

                  . 'x' . $dtime[2] . $dtime[3]

                  . 'x' . $dtime[0] . $dtime[1];

        eval('$hexdtime = "' . $hexdtime . '";');

        $fr   = "x50x4bx03x04";

        $fr   .= "x14x00";            // ver needed to extract

        $fr   .= "x00x00";            // gen purpose bit flag

        $fr   .= "x08x00";            // 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 = "x50x4bx01x02";

        $cdrec .= "x00x00";                // version made by

        $cdrec .= "x14x00";                // version needed to extract

        $cdrec .= "x00x00";                // gen purpose bit flag

        $cdrec .= "x08x00";                // 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

            "x00x00";                             // .zip file comment length

    } // end of the 'file()' method

} // end of the 'PHPZip' class

?>

php如何压缩一个文件夹里面所有的文件到zip文件里面?

//函数:文件压缩

//压缩参数:需要压缩的文件或文件夹(文件可为数组),压缩后的zip文件名及存放路径,压缩类型1:文件夹2:文件,后续操作1:压缩后下载;2:存放在服务器上(默认为/@Upload下)

//压缩文件夹示例:Tozip("./","".date("d-H-i-s").".zip",1,2);

//压缩文件示例:

// $aaa=array("1.txt","2.txt");

// Tozip($aaa,"2.zip",2);FunctionTozip($Path,

$ZipFile,

$Typ=1,

$Todo=1){//IF(!is_writeable($Path)){Exit("文件夹不可写!");}$Path=Str_iReplace("\\","/",($Path));IF(Is_Null($Path) OrEmpty($Path) Or!IsSet($Path)){ReturnFalse;}IF(Is_Null($ZipFile) OrEmpty($ZipFile) Or!IsSet($ZipFile)){ReturnFalse;}

Include_once("inc/Class_Zip.php");$zip=NewPHPZip;IF(SubStr($Path,-1,1)=="/"){$Path=SubStr($Path,0,

StrLen($Path)-1);}

OB_end_clean();Switch($Typ){Case"1":$zip-ZipDir($Path,

$ZipFile,

$Todo);Break;Case"2":$zip-ZipFile($Path,

怎样用php压缩解压rar,zip文件?

要用PHP压缩解压文件,常用的方法是调用命令行去执行解压缩操作

可以用exec()

、system()等函数调用shell命令

Linux下解压缩命令是tar

[-cxtzjvfpPN]

文件与目录,tar命令可以压缩解压.tar、.gz、.tar.gz、.tgz、.bz2、.tar.bz2、.Z、.tar.Z、.zip这些类型的文件

Linux下默认无法使用rar格式的,要另外安装RAR

for

Linux,然后使用rar和unrar命令解压缩rar格式的压缩文件

php 数组追加

在PHP里面,往数组中追加元素最简单的方法是使用[]赋值,例如需要在$arr添加一条123的语句是$arr[]=123,可以参考下面的代码:

<?php

$arr=[123,456];

print_r($arr);

$arr[]=789;

print_r($arr);

?>

扩展资料:

PHP函数

constant() 函数返回常量的值。

connection_status() 函数返回当前的连接状态。

connection_aborted() 函数检查是否断开客户机。

zip_read()() 函数读取打开的 zip 档案中的下一个文件。

zip_open() 函数打开 ZIP 文件以供读取。

zip_entry_read() 函数从打开的 zip 档案项目中获取内容。

zip_entry_open() 函数打开一个 ZIP 档案项目以供读取。

参考资料来源:百度百科-PHP (超文本预处理器)

编译PHP提示zip错误,请问怎么解决

vi /etc/ld.so.conf.d/local.conf //创建local.conf

/usr/local/lib //添加输入

ldconfig -v //执行命令

为什么php创建zip文件不管用

请参考php手册,函数特点-压缩与归档扩展部分

下面是手册实例一:

<?php

$zip = new ZipArchive();

$filename = "./test112.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {

    exit("cannot open <$filename>\n");

}

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");

$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");

$zip->addFile($thisdir . "/too.php","/testfromfile.php");

echo "numfiles: " . $zip->numFiles . "\n";

echo "status:" . $zip->status . "\n";

$zip->close();

?>

关于phpzip函数的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于phpzip函数 phpize的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did207172
更新时间:2023-05-03   阅读:18次

上一篇: php正数变成负数 java正数变负数

下一篇:php破解源码 破解phpstorm

相关资讯

最新资料更新

  • 1.php项目补充redis php+redis
  • 2.php中套js代码 js中写php代码
  • 3.文章加载更多php php加载html
  • 4.php求100的质数 php求出1100的素数
  • 5.redis缓存类php php redis页面缓存
  • 6.基于php在线聊天 php 在线聊天
  • 7.php网站后台demo php后端模板
  • 8.php比较运算符价格 php中用于比较字符串的函数
  • 9.包含苏州软世通php的词条
  • 10.phpstorm写前端 phpstorm写html
  • 11.php图书管理系统 php图书管理系统全部代码
  • 12.php多继承的作用 php继承关键字
  • 13.php英国时区代码 英国时区缩写
  • 14.php解压gz效率 rarphp文件怎么解压
  • 15.如何阅读php源码 php在线源码获取
  • 16.form居中显示php form居中显示
  • 17.php中catch的简单介绍
  • 18.朔州php后台开发 朔州php培训招聘
  • 19.php变量获取图片 php调用图片
  • 20.php类方法 php类方法访问变量

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网」
[ SiteMap ]