Decompress the compressed file instance source code in php

Source: Internet
Author: User
I carefully studied the efficiency of the decompression program written in php, which is much higher than I thought. since it is so good, I just need to optimize it and use it in my background, although the control panel in most of the space currently has the compression and decompression function, it is sometimes troublesome. do this... I carefully studied the efficiency of the decompression program written in php, which is much higher than I thought. since it is so good, I just need to optimize it and use it in my background, although the control panel in most of the space currently has the compression and decompression function, it is sometimes troublesome.

Before doing this, I have never touched on php compression. I have searched some websites on the internet. most of them are php compression classes and compression functions. if there are few hundred lines, there will be thousands of lines of code, this is hard for a newbie like me to understand. besides, I don't need such complex functions. finally, after reading the function manual and figuring out a few related functions, you will understand how to complete it.

PHP Zip File function

Remember to enable zip and remove the semicolon before extension = php_zip.dll in php. ini.

Sample code:

 ". $ I ++." This file has been skipped. cause: the file is too large.-> ". iconv (" gb2312 "," UTF-8 ", $ file_name )."

";}}// Close the current zip_entry_close ($ dir_resource) ;}// close the zip package zip_close ($ resource); $ endtime = explode ('', microtime ()); // Extract end time $ thistime = $ endtime [0] + $ endtime [1]-($ starttime [0] + $ starttime [1]); $ thistime = round ($ thistime, 3); // retain 3 as a decimal echo"

Decompress the package !, This decompression takes $ thistime seconds.

";}$ Size = get_zip_originalsize('331101.zip ', '1 generation Kerui/');?>

It took 300 seconds to decompress a small file with a size of more than 0.115 KB. it took more than 20 seconds to decompress a web file with a size of more than 30 MB.

Php decompression program

Compared with the system, it is indeed a little slower, but it is also very good, just getting started, the code is not good, but the implementation of understanding pressure, and the code is also easier to understand than the introduction of the Internet, if you see this article, I believe it is helpful to you. The program uses the running time. for details, see the code below:

// Read a maximum of 6 MB. if the file is too large, skip decompression and continue to the next step.

 

This part is not doing well, so it is impossible to decompress the large file, and will be optimized later.


Article address:

Reprint at will ^ please include the address of this 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.