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.
Uploading and Extracting Compressed files
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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
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
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)
.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)
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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
http://www.php.net/manual/en/ref.bzip2.php