Hello for some reason I can’t get my program to see if my file is empty or not if something is selected it should not go through but it is. Here is the code
if (empty($_FILES['file'] ) )
{
echo "testing";
$seterror =1;
returnBack();
}
The language construct
empty()and arrays in PHP do not mix well. In addition, if you have a<input type='file' name='file' />in your form, you will get a$_FILES[]array. You should be doingif( !array_key_exists('file', $_FILES) ) { // no file uploaded }to start with.In fact, you should be doing several checks:
fileelement is populated in$_FILES$_FILES['file']['error']== 0)Only of all of those are true will you have a file to process. Otherwise you don’t.
I’ve found following these steps religiously on a file upload handler to be thoroughly reliable.