为什么来自w3schools的上传脚本没有在我的Apache2 Ubuntu服务器上传?

Apologies in advance if this question is too remedial. This board seemed the most website matter. Now then...

I went to this site, "http://www.w3schools.com/php/php_file_upload.asp" and followed their instructions exactly, but my selected .png file just won't upload to my www/upload folder.

In my index.php file, I have:

<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

in my www/upload_file.php I have:

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

In my /www folder, I have an inner folder named "upload".

When I try to upload a file "Anon.png", I get...

Upload: Anon.png
Type: image/png
Size: 9.7392578125 kB
Temp file: /tmp/phpA2HFaj
Stored in: upload/Anon.png

Since I followed the instructions provided, I would assume that there would then be a file named "Anon.png" inside the folder "upload". But there is no such file there. Why not?

Note that I am running Apache2 with default settings on an Ubuntu13.10 server.

I had previously created the /upload folder in the /www directory but that folder did not have full write permission for user, group, and other. Fixed that and increased the file upload size limit above 20k and it works. Sorry.

Lesson learned: check the folder permissions. chmod it.

It appears that that script doesn't do anything to create the "upload" directory. It looks like it expects you to create it for it.

The script isn't checking for errors when using commands like move_uploaded_file, so it probably doesn't even know that the command has failed.

I had previously created the /upload folder in the /www directory but that folder did not have full write permission for user, group, and other. Fixed that and increased the file upload size limit above 20k and it works. Sorry.

Lesson learned: check the folder permissions. chmod o+w it.