Avatar is not uploaded to the server. I did these lessons . Those. The form with the field for loading looks like this:

<form action="save_user.php" method="post" enctype="multipart/form-data"> <input type="file" name="fupload" size="20" maxlength="255"> </form> 

The fact is that the script given in the lessons does not even perform the download, because the condition is not satisfied. The fupload element in the post request array is not at all. Why?

Here is the script itself checking the existence of the variable fupload:

 if (isset($_POST['fupload'])) { $fupload = $_POST['fupload']; $fupload = trim($fupload); if ($fupload == '') { unset($fupload); } } if (!isset($fupload) or $fupload == '') { $avatar = "avatars/net-avatara.jpg"; } 

    3 answers 3

     $fupload = isset($_POST['fupload']) ? $_POST['fupload'] : null; $avatar = is_null($fupload) ? "avatars/net-avatara.jpg" : "Загружен стандартный аватар"; 

    made such a reincarnation into 2 ternary operators :)

    • Still does not work. Equates constantly "avatars / net-avatara.jpg"; - Alexey Emelyanenko pm
    • Mean $ _POST ['fupload'] does not exist! Write on page save_user.php print_r ($ _ POST); and see what comes up at all. If empty by typo probably somewhere - johniek_comp
    • You're right. I looked - there are all variables except fupload. But the whole point is that when I changed the type of the field with file to text, everything all appeared and worked. What kind of garbage? How to explain it? - Alexey Emelyanenko
    • 2
      There is a separate $ _FILES array for the file, and you had $ _POST - johniek_comp

    for type = "file" it is necessary to consider an array of $ _FILES, where each element has a key - the name from your input field

      In your first example, $ _POST ['fupload'] changes to $ _FILES ['fupload'] - and everything works.

      http://php.su/learnphp/vars/?reserved#post http://php.su/learnphp/vars/?reserved#files

      Also look towards the $ _REQUEST array. Often it is very convenient.