Codeigniter unzip uploaded file


















Connect and share knowledge within a single location that is structured and easy to search. 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? 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:.

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.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Using getFiles is more appropriate. You can check that a file was actually uploaded via HTTP with no errors by calling the isValid method:.

As seen in this example, if a file had an upload error, you can retrieve the error code an integer and the error message with the getError and getErrorString methods. The following errors can be discovered through this method:. You can retrieve the original filename provided by the client with the getName method. This will typically be the filename sent by the client, and should not be trusted. If the file has been moved, this will return the final name of the moved file:. Always returns the original name of the uploaded file as sent by the client, even if the file has been moved:.

To get the full path of the temp file that was created during the upload, you can use the getTempName method:. This is NOT a trusted source. For a trusted version, use guessExtension instead. Returns the mime type mime type of the file as provided by the client. This is NOT a trusted value. If the mime type is unknown, will return null. This is often a more trusted source than simply using the extension provided by the filename. Each file can be moved to its new location with the aptly named move method.

This takes the directory to move the file to as the first parameter:. By default, the original filename was used. You can specify a new filename by passing it as the second parameter:.

The move method returns a new File instance that for the relocated file, so you must capture the result if the resulting location is needed:. Working with groups of files can be cumbersome, so the framework supplies the FileCollection class to facilitate locating and working with groups of files across the filesystem. At its most basic, FileCollection is an index of files you set or build:. Note: Most PHP installations have their own limit, as specified in the php. Usually 2 MB or KB by default.

This can be useful if you would like the file saved with a name that can not be discerned by the person uploading it. This is recommended. DO NOT disable this option unless you have no other option as that would cause a security risk. DO NOT turn off this option if your upload directory is public, as this is a security risk.

The path to the directory where the upload should be placed. The mime types corresponding to the types of files you allow to be uploaded. If set CodeIgniter will rename the uploaded file to this name. If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. The maximum size in kilobytes that the file can be.



0コメント

  • 1000 / 1000