Vessio Weblog

Download & Extract .ZIP Files Using PHP

February 24th, 2010

I will provide a brief overview explaining how to use PHP to automatically download a zip file from a web address and extract its contents into a new directory within your web server. This may not be a functional requirement that many PHP developers face when creating a system, however, having the ability to easily implement this task when needed will surely save time and headache.

The process is simple, there are two main configuration files that need to be called, when the first file is called the script will download your .ZIP file and place it in a directory on your server. When the second file is called the script takes the downloaded .ZIP file and will extract the contents into a new directory.

You can download the source package for PHPExtract which contains a fully functional version of the script.

The configuration files found in the “phpextract” directory are:

pull-data.php
process-data.php

Once you have customized your configuration files, upload the “phpextract” directory to your server and set write permissions for the “data” directory.

Personally, I use Cron to call each file, which usually fits my requirements with adjusting the Cron times. There are many methods to call each file as well as uses for the script, feel free to dissect if needed.

If you should require assistance with this script or assistance in customization, post a comment below and we will be glad to help you out.

Applications & Downloads, Design & Development, News & Events, Tools & Resources

2 Responses to “Download & Extract .ZIP Files Using PHP”

Mick

Hi,

It is a very good script! Thanks!

But, an improvement would be also very useful for security.

It would be possible to remove files at the time of the extraction?

I use this function with PclZip.

Method PclZip::delete()
http://www.phpconcept.net/pclzip/user-guide/58

Thanks! Mick

Mike Danna

Thank you for the feedback Mick, I am glad you found the script useful. We are working on an upgraded build to release as a utility product which will cover added security. I will be sure to note to add in a nice file removal feature as you pointed out.

Leave a Reply