Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if file field is empty in codeigniter?

I have a form with a file field called image, but this field is not required.
When user don't choose any file in form, the do_upload() always return a error.
How can I check if user chosen a file before perform the upload action in my controller?

like image 209
squiter Avatar asked Dec 19 '12 13:12

squiter


People also ask

How do you check if a file field is empty?

if(! empty($_FILES['myFileField'])) { // file field is not empty.. } else { // no file uploaded.. }

How do you check if $_ files is empty in PHP?

You can check if there is a value, and if the image is valid by doing the following: if(empty($_FILES['cover_image']['tmp_name']) || ! is_uploaded_file($_FILES['cover_image']['tmp_name'])) { // Handle no image here... }

How check file is empty in laravel?

x check if file uploaded or not using hasFile or isValid. It is very easy to check if uploaded file or image empty or not if you are using core PHP. But as we know laravel 5 provide us object of file, So we can not determine using empty(). However, we can simply do it using hasFile() and isValid() of laravel predefine.

How check input type is empty or not in jQuery?

length property in jQuery to check the file is selected or not. If element. files. length property returns 0 then the file is not selected otherwise file is selected.


1 Answers

Please use empty()

if (empty($_FILES['userfile']['name'])) {
}
like image 141
Vinoth Babu Avatar answered Sep 16 '22 15:09

Vinoth Babu