开发者

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 d开发者_如何学运维o what I need, I could really do with some advice please?

Thanks


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜