I have a form with few inputs and a file input.
I want to check whethere the file input is empty or not.
If it is empty do not try to upload, if it is not then try to upload it.
I tried something like this:
$upld_file = $this->upload->data();
if(!empty($upld_file))
{
//Upload file
}
you use codeigniter’s file uploader class… and call
$this->upload->do_upload();in a conditional statement ahd check if its true.The user_guide explains this in detail: http://codeigniter.com/user_guide/libraries/file_uploading.html
However,
if you are dead set on checking whether a file has been “uploaded” aka.. submitted BEFORE you call this class (not sure why you would). You can access PHPs
$_FILESsuper global.. and use a conditional to check if size is > 0.http://www.php.net/manual/en/reserved.variables.files.php
Update 2: This is actual working code, i use it on an avatar uploader myself using CI 2.1