-1

I am using the simplest method to upload an image file, but I'm getting an error.

My code:

<?php 
    $targetfolder = "uploads/";
    $targetfolder = $targetfolder . basename( $_FILES['file']['name']);
    if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder)) {
        echo "The file ". basename( $_FILES['file']['name']). " is uploaded";
    } else {
        echo "Problem uploading file";
    }
?>

What am I doing wrong in my code?

The error:

Notice: Undefined index:upload\upload.php on line 3
Notice: Undefined index:upload\upload.php on line 4

HTML FORM

 <form enctype="multipart/form-data" action="upload.php" method="POST">
 <input type="hidden" name="MAX_FILE_SIZE" value="300000000" />
 Send this file: <input name="file" type="file" />
 <input type="submit" value="Send File" />
 </form>
Syed
  • 25
  • 1
  • 7

1 Answers1

0

According to your error, the file haven,t been uploaded to your server side. Please cheak your post_max_size in your php.ini file. If this value is small than you uploading file, will cause the error you explained, remember that, post_max_size should at least be a little bigger than you uploading file. Another parameter you need to config is the upload_max_size in the php.ini, too.

php.ini is somewhere like

/etc/php5/apache2/php.ini
LF00
  • 27,015
  • 29
  • 156
  • 295