Codeigniter and download zip files

I am currently creating a backend for the site using the codeigniter framework, I got into a problem, I need the user to be able to upload a ZIP folder with images, when filling out the form, the ZIP folder should unzip the files, and the files need to be transferred to the folder where on the server there is a miniature version of each created image and add the file name to the database, and also, if the images are for a type of content that does not exist yet, then I need to create a directory with this type of content.

I know that Codeigniter has a loading class, but I'm not sure that it has the ability to do what I need, could I really do some advice, please?

thank

+3
source share
2 answers

You cannot check the image or file using the Upload class. The download class will allow you to accept the file and check if it is a ZIP, but how much it will go.

From there, unzip the file and just make some simple PHP in the files to check that they are the right type and make folders, etc. I would put this logic in a new library so that it is properly divided.

+3
source

As Yang noted, this is a broad question (for example, 3 or 4 questions). I am not aware of the CodeIgniter structure, 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/');
+4
source

Source: https://habr.com/ru/post/1725614/


All Articles