当前位置:Gxlcms > PHP教程 > UnzipfileswithPHP

UnzipfileswithPHP

时间:2021-07-01 10:21:17 帮助过:34人阅读

I've been looking everywhere on how to do this, and I've been noticing lots of searches to the site looking for this. So I finally figured out how to do it, and am puting my findings here for you.

The first thing you'll need to do is make sure you have the ZZIPlib library installed. If you have WHM, goto the Apache Build page, and just build apache with the "Zip" checkbox checked. That simple.

So what I've done is created a script that unzips the file "zip.zip" to the folder "zip". You should know that if the zip file contains folders, the code below will not create those folders, but this should be enough to get you going on your own.

Unzip File PHP Code

Zip files usually have more than one file inside them, so when you open a zip file you need to go through each file. That is what the zip_read and zip_entry_read functions are doing.

zip_read is getting all the info for each file, and zip_entry_read is getting the file contents from the info returned by zip_read.

zip_entry_name returns the path of the file within the zip. If the file is in a folder inside the zip, you'll need to create the directory before trying to write the file.

So there you have it: How to unzip a zip archive with PHP!

From: http://www.timlinden.com/blog/website-development/unzip-files-with-php/

人气教程排行