How do I unzip the. tar.gz. gzip. GZ Type Document
I want to upload a document to the server, in a format that may be tar.gz or gzip, or it may be a GZ format document. Then unzip it via PHP.
I found some code on the Internet, can upload and unzip tar.gz format documents to the server, other formats such as gzip, GZ can not upload the successful decompression (that is, the server upload directory no files).
PHP Code
$zipFile = $_files["File" ["Tmp_name"]; $zp = @fopen ($zipFile, "R"); $fp =popen (' Tar xzf---overwrite--directory= '. $ Uploaddir. ' /', ' W '), while ([email protected] ($ZP)) { $string = @fread ($ZP, 4096); @fwrite ($fp, $string, strlen ($string)); } @fclose ($ZP); @pclose ($FP);
I saw on the Internet that using the Phardata class can be achieved, but I do not understand.
How do I deal with multiple format decompression? Thank you!
------Solution--------------------
Just try to see if you can support the few formats above you.
$zip = new Ziparchive;
if ($zip->open (' test.gzip ') = = = TRUE) {
$zip->extractto ('./test/');
$zip->close ();
------Solution--------------------
Can not find, judge the file suffix, and then directly use the system to send the command to extract it.
TAR-ZXVF xxx.tar.gz
Bunzip Xxx.gzip
...
------Solution--------------------
If you don't want to link so in, it's best to compile PHP yourself.