0

Why this php code shows me error as

Notice: Undefined index: f in E:\xampp\htdocs\tests\file handling\file_upload1.php on line 7

Please help me out

<?php
     echo '<form action="file_upload1.php" method="POST" enctype="multipart/form-data">
         <input type="file" name="f"><br><br>
         <input type="submit" value="upload">
     </form>';

     $name=$_FILES['f']['name'];
     echo $name;    
?>
1

1 Answer 1

1

in this example you first check if $_FILES['f'] actually exists:

<?php
 echo '<form action="file_upload1.php" method="POST" enctype="multipart/form-data">
     <input type="file" name="f"><br><br>
     <input type="submit" value="upload">
 </form>';

 $name=($_FILES['f'])?$_FILES['f']['name']: '';
 echo $name;   

or try something like this:

$name='';
if(isset($_FILES['f']){
    $name=$_FILES['f']['name'];
}

the problem is that on the same page as you create the form you want to use a variable that hold the sended file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.