Get the App
SLTechnology News&Howtos  ›  Development  › 

How to decompress rar File and zip File by php

Shulou Source: shulou.com Published: 2022-06-03 15:47:13 10月13日 Update

This article mainly explains the "php how to extract rar files and zip files", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php how to extract rar files and zip files" bar!

There are many examples on the zip file network, rar file decompression php does not have direct support, you can use pecl to http://pecl.php.net/package/rar to download the corresponding version of non-thread-safe dll and then throw it into php's ext directory.

Open php.ini.

Add a line

Extension=php_rar.dll

Restart the web server and php

The copy code is as follows:

Public function _ unzip ($fileName,$extractTO) {

$fileName = iconv ('utf-8','gb2312', "upload/zip/ August .rar")

$extractTo = "upload/zip/TEST/"

$rar_file = rar_open ($fileName) or die ('could not open rar')

$list = rar_list ($rar_file) or die ('could not get list')

/ / print_r ($list)

Foreach ($list as $file) {

$pattern ='/\ ". * /'

Preg_match ($pattern, $file, $matches, PREG_OFFSET_CAPTURE)

$pathStr=$matches [0] [0]

$pathStr=str_replace ("\",'', $pathStr)

/ / print_r ($pathStr)

$entry = rar_entry_get ($rar_file, $pathStr) or die ('entry not found')

$entry- > extract ($extractTo); / / extract to the current dir

}

Rar_close ($rar_file)

}

Thank you for your reading, the above is the content of "php how to extract rar files and zip files". After the study of this article, I believe you have a deeper understanding of how php decompresses rar files and zip files, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Files learning code content security one line examples that is ideas situations articles more servers versions directories knowledge knowledge points articles threads follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia Apple Shulou Technology Xiaomi