Created
May 5, 2015 04:24
-
-
Save GoldenEra/6ee209a75bcfa34ce600 to your computer and use it in GitHub Desktop.
php:extract zip and rar file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* extract rar or zip file | |
* | |
* @since [1.0] | |
* @author Richard | |
* @date 2015-05-05 | |
* | |
* @param [string] $file_path ["D:\file\path\a.rar"] | |
* @param [string] $to_path ["D:\extract\to\path"] | |
* @return [boolean] | |
*/ | |
function extract_file($file_path, $to_path = "./") | |
{ | |
$file_type = substr($file_path, strrpos($file_path, '.') - strlen($file_path) + 1); | |
if ("zip" === $file_type) { | |
$xmlZip = new ZipArchive(); | |
if ($xmlZip->open(__DIR__."/xml.zip") === true) { | |
$xmlZip->extractTo($to_path); | |
echo "extract success"; | |
} else { | |
echo "extract fail"; | |
return false; | |
} | |
} elseif ("rar" == $file_type) { | |
$rar_file = rar_open($file_path) or die("Can't open Rar archive"); | |
$entries = rar_list($rar_file); | |
if ($entries) { | |
foreach ($entries as $entry) { | |
echo 'Filename: ' . $entry->getName() . "\n"; | |
$entry->extract($to_path); | |
} | |
rar_close($rar_file); | |
} else{ | |
echo "extract fail"; | |
return false; | |
} | |
} | |
} |
how did u install the rar php extension?
how did u install the rar php extension?
cool, thx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!