Udders
Udders

Reputation: 6976

Codeigniter and uploading zip files

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

Upvotes: 3

Views: 3166

Answers (2)

Phil Sturgeon
Phil Sturgeon

Reputation: 30766

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.

Upvotes: 3

Alix Axel
Alix Axel

Reputation: 154553

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/');

Upvotes: 4

Related Questions