3

I am currently building a backend to a site using the codeigniter framework, I have hit a bit of a problem, I needing a way to allow the user to upload a zipped folder of images, on completing the form, zipped folder must be unzipped, and the files need to be moved to a folder else where on the server, have thumbnail version of each image created and have there file name add to the DB, and also if the images are for a content type that does not already exist then I need to make a directory with that content type.

I know there is an upload class in Codeigniter, but I am not sure that, that has the capabilities do what I need, I could really do with some advice please?

Thanks

Udders
  • 6,914
  • 24
  • 102
  • 194
  • this is quite a broad question and a specific problem. With what part are you having problems with? – Jan Hančič Dec 14 '09 at 14:09
  • The particular problem i am having is that I cannot work out a way to unpack the zip and cycle through all the contents. – Udders Dec 14 '09 at 14:32

2 Answers2

4

As Jan pointed out, this is a broad question (like 3 or 4 questions). I'm not up to date with the CodeIgniter framework but to Unzip the files you can do something like this:

function Unzip($source, $destination)
{
    if (extension_loaded('zip') === true)
    {
        if (file_exists($source) === true)
        {
            $zip = new ZipArchive();

            if ($zip->open($source) === true)
            {
                $zip->extractTo($destination);
            }

            return $zip->close();
        }
    }

    return false;
}

Unzip('/path/to/uploaded.zip', '/path/to/extract/');
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
3

You wont be able to do any of the image or file checking using the Upload class. The upload class will let you accept the file and check it is a ZIP but that's as far as it will go.

From there, unzip the file and just do some simple PHP on the files to check they are the right type and make your folders etc. I would put this logic in a new library to keep it separated correctly.

Phil Sturgeon
  • 30,637
  • 12
  • 78
  • 117
  • Thanks phil, think that might just what I was looking for :-) – Udders Dec 14 '09 at 14:50
  • Hi, the link you provided is broken. Can you please update it? – Akshit Arora Sep 30 '15 at 12:45
  • That package is here: https://github.com/philsturgeon/codeigniter-unzip I'd recommend you use anything else than this. Even if you're using CodeIgniter, you should be going to Packagist and installing generic packages instead. Try this https://packagist.org/search/?tags=unzip – Phil Sturgeon Dec 03 '15 at 15:15