Ask how to decompress. tar.gz. gzip. GZ Type Documents

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.