PHP zip extension, unzip file, Ziparchive class

Source: Internet
Author: User
Tags zip extension ziparchive

<?PHP$zip=NewZiparchive ();//Create a new object/*$zip->open The first parameter of this method represents the zip file name processed. The second parameter represents the processing mode, ziparchive::overwrite means that if the zip file exists, it overwrites the original zip file. If the parameter uses Ziparchive::create, the system will add content to the original zip file. If you are not adding content to a zip file more than once, we recommend using Ziparchive::overwrite. Using these two parameters, if the zip file does not exist, the system will be automatically created. If the operation on the zip file object succeeds, $zip->open This method returns True*/if($zip->open (' Demo.zip ', ziparchive::overwrite) = = =TRUE) {    /*all properties in the Ziparchive class*/    Echo $zip->status;//status of the Zip Archive    Echo $zip->statussys;//System State of the Zip Archive    Echo $zip->numfiles;//number of files in compressed package    Echo $zip->filename;//The file name in the file system, containing the absolute path    Echo $zip->comment;//comments for compressed packages    ////////////////////////////    /*common methods in the Ziparchive class*/    $zip->addemptydir (' CSS ');//Create an empty folder in the Zip archive, return TRUE on success, or return FALSE on Failure    $zip->addfile (' index.html ', ' in.html ');//add a file to the zip directory, and name it in.html, the second argument can be omitted    $zip->addfromstring (' in.html ', ' Hello World ');//add content to a file in Zip    $zip->extractto ('/tmp/zip/');//unzip the file under the/tmp/zip/folder    $zip->renamename (' in.html ', ' index.html ');//Rename the file inside the zip    $zip->setarchivecomment (' Do-what-you-love,love ');//set comments for a compressed package    $zip->getarchivecomment ();//get comments for a compressed package    $zip->getfromname (' index.html ');//get the contents of a compressed package file    $zip->deletename (' index.html ');//Deleting Files    $zip->setpassword (' 123456 ');//set the password for a compressed package    $zip->close ();//Close Resource Handle    ////////////////////////////    }Else{    Echo' File open failed ';}

PHP zip extension, unzip file, Ziparchive class

Related Article

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.