php安装php_rar扩展实现rar文件读取和解压的方法

yipeiwu_com5年前PHP代码库

本文实例讲述了php安装php_rar扩展实现rar文件读取和解压的方法。分享给大家供大家参考,具体如下:

PHP Rar Archiving 模块 (php_rar) 是一个读取和解压rar文件的模块,但不提供RAR压缩(打包)的功能。

1.首先要到PECL的RAR页面下载DLL. 根据自己的情况选择下载对应版本的DLL.

PHP版本要求:php_rar模块适用于php 5.2及以上, 不过对于windows系统,似乎只有php5.3 / 5.4对应的DLL下载。

2.下载到的是个zip包,将其中的php_rar.pdb和php_rar.dll两个文件解压到PHP安装目录下的ext子目录中。

3.在php.ini中加入一行php_rar扩展引用声明 extension=php_rar.dll

4.如果使用Apache服务器,就需要重启Apache。IIS下以FastCGI模式加载的PHP则不需要进一步操作了。

5.写个测试文件看看有没有问题啊

6.如果有问题,查看服务器的日志文件。

附官方的测试代码test-rar.php :

<?php
$archive_name = '/full/path/to/file.rar'
$entry_name = 'path/to/archive/entry.txt'; //notice: no slash at the beginning
$dir_to_extract_to = '/path/to/extract/dir';
$new_entry_name = 'some.txt';
$rar = rar_open($archive_name) OR die('failed to open ' . $archive_name);
$entry = rar_entry_get($rar, $entry_name) OR die('failed to find ' . $entry_name . ' in ' . $archive_name);
// this will create all necessary subdirs under $dir_to_extract_to
$entry->extract($dir_to_extract_to); 
/* OR */
// this will create only one new file $new_entry_name in $dir_to_extract_to
$entry->extract('', $dir_to_extract_to.'/'.$new_entry_name); 
// this line is really not necessary
rar_close($rar);
?>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP扩展开发教程》、《php文件操作总结》、《PHP目录操作技巧汇总》、《PHP常用遍历算法与技巧总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

相关文章

PHP substr 截取字符串出现乱码问题解决方法[utf8与gb2312]

substr --- 取得部份字符串 语法 : string substr (string string, int start [, int length]) 说明 : substr(...

PHP会话处理的10个函数

PHP会话处理的10个函数

在PHP开发中,比起Cookie,Session 是存储在服务器端的会话,相对安全,并且不像 Cookie 那样有存储长度限制,这里我们详细介绍一下PHP处理会话函数将要用到10个函数。...

PHP+Apache环境中如何隐藏Apache版本

PHP+Apache环境中如何隐藏Apache版本

目前很多服务器共计都是基于软件版本针对性的共计,所以如果服务器安装的是Apache,隐藏它的版本号是非常有必要的,也是能够减少隐患的一个方法,一起来学习一下。 如何隐藏?要隐藏Apac...

PHP面向对象程序设计之接口的继承定义与用法详解

本文实例讲述了PHP面向对象程序设计之接口的继承定义与用法。分享给大家供大家参考,具体如下: 在PHP5中,接口是可以继承自另外一个接口的。这样代码的重用更有效了。要注意只有接口和接口之...

PHP中字符串长度的截取用法示例

本文实例讲述了PHP中字符串长度的截取用法。分享给大家供大家参考,具体如下: php中提供了很多使用函数,其中字符串的截取函数也不例外,而且功能也非常强大。 <?php...