Uploader

The upload class simplifies the process of uploading files to the server. Every Controller class has its own upload class.

# General

Max size

You can set the maximum allowed file size (expressed in Kb):

$this->upload->setMaxSize(1000);

You can get the maximum allowed file size this way:

$this->upload->getMaxSize();

Directory

By default every file is uploaded to the public folder. But you can change the default directory this way:

$this->upload->setDirectory('images');

This will upload any file to the public/images folder.

You can get the choosen directory this way:

$this->upload->getDirectory();

Last file

To get information about the last file uploaded, you can use the getLastFile method:

$this->upload->getLastFile();

That will return an array with information about the file name, file type, file size, directory, uploader IP, upload date and any upload error.

# Format match

You can validate a file format using the matchFormat method.

It will return true if the file matches the formats especified:

$matches = $this->upload->matchFormat('examplefile', 'jpg, png, gif'));

You can pass a string separated by commas or an array like this:

$formats = array('jpg', 'png', 'gif');
$matches = $this->upload->matchFormat('examplefile', $formats));

# Upload

First create a form in your view like this:

<form action="yourpage/upload" method="post" enctype="multipart/form-data">
     <input type="file" name="examplefile"/>
     <input type="submit" value="upload"/>
</form> 

Then in your controller create a function named upload with the following code:

//Optional configuration
$this->upload->setMaxSize(1000)->setDirectory('');

$this->upload->file('examplefile');

If the examplefile size isn't greater than 1000 Kb it will be uploaded to the public folder. You are done!