0
<?php
     $filename = $_FILES['file']['name'];
     $tempname = $_FILES['file']['tmp_name'];

     if(isset($filename)){
          //echo $filename;
          $directory = 'E:/php_uploads/';
          move_uploaded_file($tempname,$directory.$filename);
          echo 'Done';
     }
     else{
          echo 'No file selected';
     }
?>

<form method="POST" action= "fileupload.php" enctype = "multipart/form-data">
       <input type="file" name="file"><br/><br/>
       <input type="submit" value="Submit">
</form>

The enctype is correct.The element names correspond to those in the php code.So what is wrong which leads to it showing Notice: Undefined index : file in blah blah blah...?

2
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by delta_frost
1

Hi delta_frost,

You have to do it this way, as on the initial load of the page, it can't find any set $_FILE["file"], in the $_FILE global. Why? there where no form submissions yet.

     if(isset($_FILES['file'])){
         $filename = $_FILES['file']['name'];
         $tempname = $_FILES['file']['tmp_name'];
          //echo $filename;
          $directory = 'E:/php_uploads/';
0

Thanks, I was trying this by watching a tutorial by someone from thenewBoston. His code was exactly the same as mine above, but I suspect that turning error_output on to some value caused the problem.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.