0

I'm getting the error

Notice: Undefined index: file_upload in C:\MAMP\htdocs\basic_files\upload.php on line 3

When I load the page to upload the file in the form.

I know a lot of other people cite a problem with the enctype or php.ini settings as reasons for this error but I'm quite sure mine are ok. I've cleared the browser (chrome) cache and restarted the MAMP server a couple of times just to make sure but I'm still getting the error.

My php.ini settings are:

file_uploads = On
upload_max_filesize = 128M
max_file_uploads = 20
memory_limit = 128M 
max_execution_time = 30
post_max_size = 128M

My PHP is:

<?php   
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo "<pre>Max upload size: ".ini_get('upload_max_filesize')."\nMax post 
size: ".ini_get('post_max_size')."</pre>";
if (isset($_POST['submit'])) {
print_r($_FILES['file_upload']);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" 
method="post">
<input type="file" name="file_upload"><br>
<input type="submit" name="submit">
</form> 
</body>
</html>

When I click the submit button the page does nothing for a few seconds and then goes to a blank page still called upload.php.

Martin
  • 22,212
  • 11
  • 70
  • 132
  • 2
    `line 3` does not fit with the code you've displayed here. – Martin Jul 08 '19 at 13:11
  • does this error occur after you upload a file? Does this error occur only on the initial first page load? – Martin Jul 08 '19 at 13:12
  • Thanks Martin, I had to change the code after I uploaded it to Stack Overflow but its all still the same content just had to redo the indentation and spacing. The error occurs after I upload a file. It goes to a blank page then when I go back it displays the error, it does it repeatedly. – H.Harrison1993 Jul 08 '19 at 13:41
  • Amazingly its just started working, I'm at an airport so turned my laptop off to go through security and I've just turned it back on and now its working fine. Not sure what it was though annoyingly. Thanks anyway guys, have a great day :) For anyone reading this in the future, it could be that I cleared the cache on the browser that was stopping it from working for some reason, then after restarting the computer it reloaded everything again, so maybe try that. I can't be 100% sure though but hope that helps anyone else out that runs into this problem. – H.Harrison1993 Jul 08 '19 at 13:45
  • A blank page strongly implies a PHP error; you need to read the error from the **error log** and not on the screen, as screen output will be broken with a fatal error. [Please read here](https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php5-apache-fastcgi-cpanel) – Martin Jul 08 '19 at 13:45
  • hahaha I would view being in an airport a security risk for your work . Glad it's fixed. If so, please delete or add an answer to this question to show it's closed. Thanks – Martin Jul 08 '19 at 13:46

1 Answers1

0

Although I can't be 100% sure this was the actual fix, I think it probably was. I ensured that all the php.ini settings were correct and that the enctype was set to "multipart/formdata". Then I deleted the browser cache and turned the restarted the computer and the code started working.