<?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