很多站长朋友们都不太清楚phprar压缩,今天小编就来给大家整理phprar压缩,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 怎样用php压缩解压rar,zip文件? 2、 如何用PHP上传RAR压缩包同时解压到指定目录 3、 这是我的php环境。里面的rar咋用? 4、 为什么压缩包下载了会变成php格式?要怎么变成rar打开呢? 怎样用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上传RAR压缩包同时解压到指定目录<?php
header("content-type:text/html;charset=utf-8");
$path = getcwd();//获取当前系统目录
if($_POST['sub'])
{
$tname = $_FILES["ufile"]["tmp_name"];
$fname = $_FILES["ufile"]["name"];
move_uploaded_file($tname,$fname);
$obj=new com("wscript.shell");//使用PHP预定义的Com组件加载Shell,加载wscript.shell用来执行dos命令的组件
$obj->run("winrar x $path\\".$fname." ".$path,1,true);//所要执行的命令
unlink($fname);//解压后删除已上传的压缩文件
}
?>
<form action="" method="post" enctype="multipart/form-data">
选择要上传的文件:<input type="file" name="ufile">
<input type="submit" name="sub" value="上传压缩文件并解压">
</form>
这是我的php环境。里面的rar咋用?Windows下安装php_rar 扩展,让php实现rar文件的读取和解压,PHP Rar Archiving 模块 (php_rar) 是一个读取和解压rar文件的模块,但不提供RAR压缩(打包)的功能。
附测试代码 test-rar.php :
<?php
$rar_file = rar_open('test.rar') or die("Failed to open Rar archive");
$entries_list = rar_list($rar_file);
header('Content-Type: text/plain');
var_export($entries_list);
?>
查询手册可以获得更多函数的详细说明,该扩展支持的函数有:
Rar 函数
rar_wrapper_cache_stats — Cache hits and misses for the URL wrapper
RarArchive — The RarArchive class
RarArchive::close — Close RAR archive and free all resources
RarArchive::getComment — Get comment text from the RAR archive
RarArchive::getEntries — Get full list of entries from the RAR archive
RarArchive::getEntry — Get entry object from the RAR archive
RarArchive::isBroken — Test whether an archive is broken (incomplete)
RarArchive::isSolid — Check whether the RAR archive is solid
RarArchive::open — Open RAR archive
RarArchive::setAllowBroken — Whether opening broken archives is allowed
RarArchive::__toString — Get text representation
RarEntry — The RarEntry class
RarEntry::extract — Extract entry from the archive
RarEntry::getAttr — Get attributes of the entry
RarEntry::getCrc — Get CRC of the entry
RarEntry::getFileTime — Get entry last modification time
RarEntry::getHostOs — Get entry host OS
RarEntry::getMethod — Get pack method of the entry
RarEntry::getName — Get name of the entry
RarEntry::getPackedSize — Get packed size of the entry
RarEntry::getStream — Get file handler for entry
RarEntry::getUnpackedSize — Get unpacked size of the entry
RarEntry::getVersion — Get minimum version of RAR program required to unpack the entry
RarEntry::isDirectory — Test whether an entry represents a directory
RarEntry::isEncrypted — Test whether an entry is encrypted
RarEntry::__toString — Get text representation of entry
RarException — The RarException class
RarException::isUsingExceptions — Check whether error handling with exceptions is in use
RarException::setUsingExceptions — Activate and deactivate error handling with exceptions
为什么压缩包下载了会变成php格式?要怎么变成rar打开呢?晕,楼上的乱说,你明显就是没有把RAR下载下来的,PHP是并不是你的压缩文件,而是要你点击后,才会把隐藏的RAR文件再给你,你在网页里打开这个文件,然后进入点击,看看会不会有RAR的文件给你吧
关于phprar压缩的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于phprar压缩 php压缩zip的详细内容...