PHP file Compression zip extension

Source: Internet
Author: User
Tags zip extension ziparchive

<?php function Addfiletozip ($path, $zip) {$handler = Opendir ($path);        Opens the current folder specified by $path. while (($filename = Readdir ($handler))!== false) {if ($filename! = "." && $filename! = "...") {//Folder file name is '. ' and '. ', do not operate on them if (Is_dir ($path. "/" . $filename) {//If an object being read is a folder, the recursive Addfiletozip ($path. "/" .                $filename, $zip); } else {//Add the file to the Zip object $zip->addfile ($path. "/" .                $FILENAME);    }}} @closedir ($path);    } $zip = new ziparchive (); $file =date ("YMD"). ".    Zip "; fopen ($file, ' W '), or//In Windows environment can omit this sentence, but in the LIUNX environment, it is best to add, because in some liunx environment Ziparchive::create 
Method cannot automatically create files, will Causes file compression to fail.

if ($zip->open ($file, ziparchive::create) ===true) { if (file_exists ($file)) { addfiletozip (' Test ', $zip); Invokes the method, operates on the root directory to be packaged, and passes the Ziparchive object to the method }else{ echo "file does not exist"; } Close the processed zip file if ($zip->close ()) { return true; } else{ return false; } } else { echo "failed"; }

  

PHP file Compression zip extension

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.