Please tell me there is such a code:

<form enctype='multipart/form-data' action='/fun/editcontact.php' method='post'> <td style='border-bottom: 1px solid #e0e0e0;'><span style='display: inline-block;margin-left:10px;margin-right:15px;'><i style='margin-right:15px; font-size:20px; color:#737373;' class='far fa-image'></i>Фото: </span><input style='border-bottom: 0px solid #737373;float:right;height:auto;margin-right: -25px; name='userfile' type='file'><input type='hidden' name='file_name' value='".$row['id']."'><input type='hidden' name='MAX_FILE_SIZE' value='3000000'></td> </form> 

And php:

 <?php $uploaddir = '/home/uploads/contacts/'; $ext = pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_POST['file_name'] . '.jpg')) { print "File is valid, and was successfully uploaded."; } else { print "There some errors!"; } header("Location: *"); ?> 

When I upload an eror log file, I get this error.

[05-Nov-2018 08:23:49 UTC] PHP Notice: Undefined index: userfile in /home/editcontact.php on line 16

[05-Nov-2018 08:23:49 UTC] PHP Notice: Undefined index: userfile in /home/editcontact.php on line 17 What could be the problem? Thank.

  • and which line is 16 and 17? - Pavel Igorevich
  • @PavelIgorevich $ ext = pathinfo ($ _ FILES ['userfile'] ['name'], PATHINFO_EXTENSION); if (move_uploaded_file ($ _ FILES ['userfile'] ['tmp_name'], $ uploaddir. $ _POST ['file_name']. '.jpg')) - Vladislav Samokhin
  • See what's in $ _FILES. It will be clear what the keys are. - MAX
  • @MAX what do you mean? - Vladislav Samokhin
  • It means output $_FILES and see with your eyes what values ​​it contains. - u_mulder

1 answer 1

When loading files, the PHP Notice: Undefined index: *** in error PHP Notice: Undefined index: *** in occurs when the $ _FILES array is not defined, the error directly indicates this. Add input / button type="submit" to submit the form in action