I've created a form with 3 <input type="file"/>
I see that I get an array with array(name=>"")
.
So I check if ($_FILE["myfilename"]["name"]=="")
instead.
This works but it seems rather unusual to me.
I was wondering if there was a better way to check if a file input is set or not?
There is: is_uploaded_file()
. When dealing with uploaded files, you should always use it (and its cousin move_uploaded_file()
) for security reasons.
You can use empty to check if a variable is blank or not but Pekka's solution is best in this way
if (empty($_FILES["myfilename"]["name"]))
If you are checking that if a variable is set you can use isset function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With