Upload Element
The following method will add a file upload element to the form utilizing the form_upload() form helper function.
upload (string name|id [, string label, bool required, string|array attributes])
- name|id: adds name and id attributes to the element (where id is optional)
- label: adds a label element to the label position
- required: if set to TRUE a file will be required
- attributes: adds attributes or file upload preferences to the element (as string or array)
Note: This method will automatically add the parameter enctype="multipart/form-data" to the opening form tag.
Usage Example
// assuming that $nameasid = TRUE was set in the config file
// so we don't need to worry about supplying an element id
$this->form->upload('file', 'Upload File', '', 'allowed_types=pdf|zip, max_size=4000')
or
// using a config array for preferences instead
// please note that this can also be saved in the config file
$config = array(
'upload_path' = '/var/www/vhosts/example/dir', // the absolute or relative path to the folder where the upload should be placed
'allowed_types' = 'pdf|zip',
'max_size' = 4000
);
$this->form->upload('file', 'Upload File', '', $config)
For all possible upload preferences please take a look at the File Uploading Class / Preferences section in the CodeIgniter user guide.
will produce
<label for="file">Upload File</label><input type="file" name="file" id="file" />
and will only allow .pdf and .zip files that do not exceed the file limit of 4000 bytes