Php implements batch compression and download of website files

Source: Internet
Author: User
Tags ziparchive
This article mainly introduces php's function of compressing and downloading website files in batches. It provides an example of compressing files into zip format, if you are interested, you can refer to using php to batch compress files and download them. this class will be used in this process. before using this class, you must enable zlib in linux, for windows, you need to cancel the comments before php_zip.dll. Below is a simple example of compressing a file into a zip format. For more information about the usage, see php documentation.

<? Php program filename='test.zip '; // The final generated file name (including path) if (file_exists ($ filename) {unlink ($ filename );} // regenerate the file $ zip = new ZipArchive (); if ($ zip-> open ($ filename, ZIPARCHIVE: CREATE )! = TRUE) {exit ('file cannot be opened, or file creation failed');} $ datalist = array ('Try. php ', 'zip _ class. php '); foreach ($ datalist as $ val) {if (file_exists ($ val) {$ zip-> addFile ($ val );}} $ zip-> close (); // close if (! File_exists ($ filename) {exit ('file cannot be found '); // even if the file is created, it may still fail}

The above is the idea that php implements bulk compression of all the content for file download and packaging. we can also use php to call the shell script of linux to implement this function, I hope you can study it.

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.