Uploading and Extracting Compressed files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Uploading and Extracting Compressed files

Post by mchaggis »

Hi,

I am writing a gallery application, and rather than just giving the user the abbility to upload images individually, or x number at a time, I would like to give them the ability to upload a compressed file, be it a zip, tar or gz'd tar file.

Once uploaded, I want the script to extract all the images and add them to the gallery as if they had been uploaded individually.

Anyone go any suggestions, I know that I can use the command line programs for these file types and do it that way, but I am wonder if:
a) there is an easier way
b) what the easiest way of distingiushing between the diffrent compressed file types is.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It'd be tricky to ensure the extraction would work since it depends how they are compressed and if they have been compressed correctly.

But in essence, my approach would be:

1. preg_match and the filename to check its extension
2. Decide on the archive type and the command used to unzip it
3. Use system() or exec() to run the command to unzip the file to a specified folder

I cannot see any other way to do it unfortunately although somebody else may do.

Maybe it will be of some use if you haven't already considered this approach :D
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

Yeah that was my thoughts, I just hopd there would be a nicr way of doing things with detecting compressing, but I suppose I could use the following tools:

.zip - gunzip (or is it just unzip)
.tar.gz - tar -zx
.tar - tar - x


There are other compressoin type out there but I think this covers the major bases, if anyine else can suggest another other compression programs etc (linux based is a must) :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'd include RAR too.... thats pretty popular.

ACE was popular for a while in windows but you never see it anymore.

I have no idea of unix tools to unzip these files though :?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Otherwise you can use Bzip compression / decompression functions and write a code to figure out how to split the files on to your server.
http://www.php.net/manual/en/ref.bzip2.php
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

bizip would be great, if it wasn't for one little problem. I cannot controll the compression type and seeing as zip is still the most popular among windose users, I guess I will need to support :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I believe there is a Zip class in the Code Snippets.. ;)
Post Reply