CodeIgniter Forums
Is file selected checking - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Is file selected checking (/showthread.php?tid=1497)



Is file selected checking - rejoan - 03-14-2015

Hi,
Is there any way to check is user browse file for upload or not? currently I am doing with this
PHP Code:
if($_FILES && $_FILES['avatar']['name']){...} 

Shouldn't there is a codeigniter way to do this? this is need because when user will select file for upload then validation operation will work. i.e file upload option is optional


RE: Is file selected checking - spjonez - 03-15-2015

There is, the do_upload method on the upload class.

Code:
...
$this->upload->initialize( $config );

if ( $this->upload->do_upload( ) === true ) {
    $file = $this->upload->data( );
}
else {
    // file was not uploaded, errors are in $this->upload->display_errors( )
}