“Notice: Undefined index”, but index appears to be defined

html page:

<form method="POST" action="Database/action.php">
    <input type="file" name="select_build" id="select_build" class="form-control">
    <input type="Submit" name="upload_build" class="form-control">
</form>

action page :

else if(isset($_POST['upload_build']))  //UPLOAD REQUEST
{ 
    $file_name=addslashes($_FILES['select_build']['name']);
    $file_size=$_FILES['select_build']['size'];
    $file_type=$_FILES['select_build']['type'];
    $temp_file=$_FILES['select_build']['tmp_name'];
    
    if(empty($file_name)){ echo "empty"; //echo displays

As you can see, the key select_build was defined, but I don’t understand why the undefined index error is triggered.

Your form requires the enctype="multipart/form-data" attribute, to handle file uploads.

2 Likes