PHPZip compression functions for file compression online _ PHP Tutorial

Source: Internet
Author: User
Tags ziparchive
PHPZip is a function used to compress files online. Copy the code as follows: * createsacompressedzipfile * functioncreate_zip ($ filesarray (), $ destination, $ overwritefalse) {ifthezipfilealreadyexistsandove The code is as follows:


/* Creates a compressed zip file */
Function create_zip ($ files = array (), $ destination = '', $ overwrite = false ){
// If the zip file already exists and overwrite is false, return false
If (file_exists ($ destination )&&! $ Overwrite) {return false ;}
// Vars
$ Valid_files = array ();
// If files were passed in...
If (is_array ($ files )){
// Cycle through each file
Foreach ($ files as $ file ){
// Make sure the file exists
If (file_exists ($ file )){
$ Valid_files [] = $ file;
}
}
}
// If we have good files...
If (count ($ valid_files )){
// Create the archive
$ Zip = new ZipArchive ();
If ($ zip-> open ($ destination, $ overwrite? ZIPARCHIVE: OVERWRITE: ZIPARCHIVE: CREATE )! = True ){
Return false;
}
// Add the files
Foreach ($ valid_files as $ file ){
$ Zip-> addFile ($ file, $ file );
}
// Debug
// Echo The zip archive ins, $ zip-> numFiles, 'files with a status of ', $ zip-> status;

// Close the zip -- done!
$ Zip-> close ();

// Check to make sure the file exists
Return file_exists ($ destination );
}
Else
{
Return false;
}
}
/***** Example Usage ***/
Optional files=array('file1.jpg ', 'file2.jpg', 'file3.gif ');
Create_zip ($ files, 'myzipfile.zip ', true );


Function code for online decompression of PHP Zip files

The http://www.bkjia.com/PHPjc/321861.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321861.htmlTechArticle code is as follows:/* creates a compressed zip file */function create_zip ($ files = array (), $ destination = '', $ overwrite = false) {// if the zip file already exists and ove...

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.