0

Ok guys, I've looked around everywhere and I cannot figure out what I am doing wrong here. The please choose file triggers but the Ok. does noes not when a file is choosen. Can someone please tell me what I am doing wrong?

<?php
    if (isset($_FILES["file"]["name"])) {
        $name = $_FILES['file']['name'];
        //$size = $_FILES['file']['size'];
        //$type = $_FILES['file']['type'];

        //$tmp_name = $_FILES['file']['tmp_name'];

        if (isset($name)){
            if(!empty($name)){
                echo 'OK.';
            }
            else{
                echo 'Please choose a file.';
            }
        }
    }
?>
<html>
<form action="upload.php" method="POST" enctype="multipart/form-data" >
    <input type="file" name="file">
    <input type = "submit" value="Submit"  name="submit">
</form>
</html>
Michael Collins
  • 380
  • 1
  • 4
  • 19

1 Answers1

1

If a file is not present the $_FILES['file']['name'] is not set.

if (isset($name)) {}

Does never fire.

JazzCat
  • 4,243
  • 1
  • 26
  • 40