PHP解压tar.gz格式文件的方法,
本文实例讲述了PHP解压tar.gz格式文件的方法。分享给大家供大家参考,具体如下:
1、运用php自带压缩与归档扩展(phar)
$phar = new PharData('song.tar.gz'); //路径 要解压的文件 是否覆盖 $phar->extractTo('c:/tmp', null, true);
2、首先需要安装pear类管理工具
linux下
/usr/local/php/bin/pear install Archive_Tar
wamp默认没有安装pear, go-pear.php 适合旧版本的 , php5.3 需要 下载 go-pear.phar
将下载的 文件放到 php目录下(任意目录下都可以) 执行 php go-pear.phar 命令,根据提示按enter即可
①、安装
#这个类实际安装pear时默认就会安装 pear install archive_tar
②、
/** 原理:tar压缩包前512字节有自己的固定格式,根据这512个字节可以获取压缩包的文件名,大小等信息 在配合 gzopen,gzread 便可以解压gz格式 */ $tar_object = new Archive_Tar("song.tar.gz"); $tar_object->extract('c:/tmp', true);
3、php调用外部命令来执行解压
//必须等命令执行完成,脚本才会推出,popen命令并非异步去执行 error_reporting(E_ALL); ini_set("display_errors", 1); $handle = popen("tar -xzvf song.tar.gz 2>&1", 'r'); /* while(!feof($handle)) { set_time_limit(3); $buffer = fgets($handle); echo "$buffer\n"; ob_flush(); flush(); }*/ echo "start \n"; pclose($handle); echo "end \n";
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP操作zip文件及压缩技巧总结》、《PHP基本语法入门教程》、《PHP错误与异常处理方法总结》及《php常用函数与技巧总结》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
- php解压文件代码实现php在线解压
- php实现zip文件解压操作
- php使用ZipArchive函数实现文件的压缩与解压缩
- php在线解压ZIP文件的方法
- php实现zip压缩文件解压缩代码分享(简单易懂)
- php 解压rar文件及zip文件的方法
- php处理文件的小例子(解压缩,删除目录)
- php zip文件解压类代码
- php zlib压缩和解压缩swf文件的代码
- php对gzip文件或者字符串解压实例参考

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment