Page 1 of 1

Uploading and Extracting Compressed files

Posted: Wed Mar 09, 2005 9:37 pm
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.

Posted: Thu Mar 10, 2005 7:39 am
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

Posted: Thu Mar 10, 2005 8:01 am
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

Posted: Thu Mar 10, 2005 8:13 am
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 :?

Posted: Thu Mar 10, 2005 8:14 am
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

Posted: Thu Mar 10, 2005 8:28 am
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 :(

Posted: Thu Mar 10, 2005 8:45 am
by feyd
I believe there is a Zip class in the Code Snippets.. ;)