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