Table of Contents
附上 PHP解压zip文件函数源码:
Home Backend Development PHP Tutorial PHP解压缩文件函数详解

PHP解压缩文件函数详解

Jun 23, 2016 pm 01:55 PM
php function document unzip Detailed explanation

欲使用本函数库需先安装 zlib,可到 http://www.zlib.net/ 取得该函数库。 )

zclose: 关闭压缩文件。

gzeof: 判断是否在压缩文件尾。

gzfile: 读压缩文件到数组中。

gzgetc: 读压缩文件中的字符。

gzgets: 读压缩文件中的字符串。

gzgetss: 读压缩文件中的字符串,并去掉 HTML 指令。

gzopen: 打开压缩文件。

gzpassthru: 解压缩指针后全部资料。

gzputs: 资料写入压缩文件。

gzread: 压缩文件读出指定长度字符串。

gzrewind: 重设压缩文件指针。

gzseek: 设压缩文件指针至指定处。

gztell: 取得压缩文件指针处。

readgzfile: 读出压缩文件。

gzwrite: 资料写入压缩文件。

gzclose 关闭压缩文件。

语法: boolean gzclose(int zp);

返回值: 布尔值

函数种类: 特殊文件格式

内容说明: 本函数将已打开的压缩文件关闭。参数 zp 为压缩文件的指针代码。成功则返回 true 值。

参考: gzopen()

gzeof 判断是否在压缩文件尾。


语法: boolean gzeof(int zp);

返回值: 布尔值

函数种类: 特殊文件格式

内容说明: 本函数用来判断目前打开的压缩文件指针是否指到文件尾 (EOF, End OF File)。参数 zp 为压缩文件的指针代码。在文件尾则返回 true 值。

gzfile 读压缩文件到数组中。

语法: array gzfile(string filename);

返回值: 数组

函数种类: 特殊文件格式


内容说明: 本函数将压缩文件读出并解压缩至数组变量中。参数 filename 为文件名称。

gzgetc 读压缩文件中的字符。

语法: string gzgetc(int zp);

返回值: 字符串


函数种类: 特殊文件格式

内容说明: 本函数将压缩文件解压缩并取出一个字符。参数 gz 为压缩文件打开代码。若至文件尾则会返回 false。

gzgets 读压缩文件中的字符串。

语法: string gzgets(int zp, int length);

返回值: 字符串

函数种类: 特殊文件格式

内容说明: 本函数将压缩文件解压缩并取出指定长度的字符串。参数 gz 为压缩文件打开代码。参数 length 为指定字符串长度加一,意即读出的字符串长度为 length-1。若至文件尾或至行尾即行停止,因此本函数通常用来读取一行。

gzgetss 读压缩文件中的字符串,并去掉 HTML 指令。

语法: string gzgetss(int zp, int length);

返回值: 字符串

函数种类: 特殊文件格式

内容说明: 本函数将压缩文件解压缩并取出指定长度的字符串,并将字符串中的 HTML 或 PHP 指令去掉,返回纯文字。参数 gz 为压缩文件打开代码。参数 length 为指定字符串长度加一,意即读出的字符串长度为 length-1。若至文件尾或至行尾即行停止,因此本函数通常用来读取一行。

gzopen 打开压缩文件。

语法: int gzopen(string filename, string mode);

返回值: 整数

函数种类: 特殊文件格式

内容说明: 本函数用来打开压缩文件。参数 filename 为文件名称。参数 mode 为开文件的状态。若有失败则返回 false 值。

使用范例,下面为部份程序

  $fp=gzopen("/tmp/gzfile.gz", "r");

?>

参考 gzclose()

gzpassthru 解压缩指针后全部资料。

语法: boolean gzpassthru(int zp);

返回值: 布尔值


函数种类: 特殊文件格式

内容说明: 本函数将已打开压缩文件文件指针后的资料全部解压缩,并输出至标准输出装置 (stdout)。参数 gz 为开文件的代码。若有失败则返回 false 值。

gzputs 资料写入压缩文件。

语法: boolean gzputs(int zp, string str, int [length]);

返回值: 布尔值

函数种类: 特殊文件格式

内容说明: 本函数其实就是 gzwrite()。参数 gz 为开文件的代码。参数 str 为欲写入的字符串。参数 length 可省略,为指定长度。若有失败则返回 false 值。

gzread 压缩文件读出指定长度字符串。语法: string gzread(int zp, int length);返回值: 字符串函数种类: 特殊文件格式内容说明: 本函数用来读取指定长度的字符串。参数 gz 为开文件的代码。参数 length 为指定长度。使用范例<?php   $filename = "/temp/sosofile.txt.gz";  $zd = gzopen($filename, "r");  $contents = gzread($zd, 10000);  gzclose($zd);?>
Copy after login

gzrewind 重设压缩文件指针。

语法: boolean gzrewind(int zp);

返回值: 布尔值

函数种类: 特殊文件格式

内容说明: 本函数将重设压缩文件的文件操作指针到文件头处。参数 zp 为开文件代码。

gzseek 设压缩文件指针至指定处。

语法: int gzseek(int zp, int offset);

返回值: 整数


函数种类: 特殊文件格式

内容说明: 本函数将重设压缩文件的文件操作指针到指定的位处。参数 zp 为开文件代码。参数 offset 为第几个位。成功则返回 0,失败返回 -1。

gztell 取得压缩文件指针处。语法: int gztell(int zp);返回值: 整数函数种类: 特殊文件格式内容说明: 本函数用来取得压缩文件的文件操作指针在某位处。参数 zp 为开文件代码。使用范例<?php   $exfile=gzopen("/tmp/haha.gz", "r");  $aline=gzgets($exfile, 80);  print("现在文件指针在第".gztell($exfile)."个位");  gzclose($exfile);?>
Copy after login

readgzfile 读出压缩文件

语法: boolean readgzfile(string filename);

返回值: 布尔值

函数种类: 特殊文件格式

内容说明: 本函数将压缩文件全部读出并解压缩,之后将内容送到标准输出设备上 (stdout)。参数 filename 为文件名称。本函数其实也可以读取非压缩文件至标准输出设备中。

gzwrite 资料写入压缩文件。

语法: boolean gzwrite(int zp, string string, int [length]);

返回值: 布尔值

函数种类: 特殊文件格式

内容说明: 本函数用来将资料写入指定的压缩文件中。参数 gz 为开文件的代码。参数 str 为欲写入的字符串。参数 length 可省略,为指定长度。若有失败则返回 false 值。


附上 PHP解压zip文件函数源码:

/********************** *@file - path to zip file  需要解压的文件的路径 *@destination - destination directory for unzipped files  解压之后存放的路径 *@Recorded  By Androidyue *@需要使用 ZZIPlib library ,请确认该扩展已经开启 */  function unzip_file($file, $destination){  // 实例化对象  $zip = new ZipArchive() ;  //打开zip文档,如果打开失败返回提示信息  if ($zip->open($file) !== TRUE) {      die ("Could not open archive");  }  //将压缩文件解压到指定的目录下  $zip->extractTo($destination);  //关闭zip文档  $zip->close();      echo 'Archive extracted to directory';  }  //测试执行  //unzip_file("1.func.zip","1");  
Copy after login
谢谢关注 websites 博客!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles