PHP Unzip the contents of the ZIP archive to the specified directory step

Source: Internet
Author: User
This time to everyone to bring PHP decompression zip package content to the specified directory step-by-bit, PHP decompression package contents to the specified directory of the attention to what, the following is the actual case, together to see.

This article introduces the PHP decompression zip package contents to the specified directory of the code, there is a need for friends to refer to.

directory structure:

Test

test/index.php
Test/test_zip.zip
Test/test_zip

<span style= "FONT-SIZE:14PX;" ><?phpheader (' Content-type:text/html;charset=utf-8 '); $filename = ' test_zip.zip '; $path = './test_zip.zip '; $ dir = ' Test_zip ', if (!is_dir ($dir)) {mkdir ($dir, 0777, true);//create directory Save extracted content}if (file_exists ($filename)) {$resource = Zip_ Open ($filename), while ($zip = Zip_read ($resource)) {if (Zip_entry_open ($resource, $zip)) {$file _content = Zip_entry_ Name ($zip);//Get file name, Mac compressed into zip, unzip need to filter repository hidden file $file_name = substr ($file _content, Strrpos ($file _content, '/') + 1); if (!is _dir ($file _name) && $file _name) {$save _path = $dir. ' /'. $file _name;if (file_exists ($save _path)) {echo ' folder already exists in file '. $file _name. ' "<pre/> ';} else {echo $file _name. ' <pre/> '; $file _size = Zip_entry_filesize ($zip); $file = Zip_entry_read ($zip, $file _size); File_put_contents ($ Save_path, $file); Zip_entry_close ($zip);}}} Zip_close ($resource);} </span>

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How PHP removes null or empty elements from an array

PHP Implements a log function

Related 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.