php - File upload issue. using the w3school tutorial -


i @ w3school tutorial upload file. can understand code. first 2 version of code works, while doesn't.

  <?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"] . " exists. ";       }     else       {       move_uploaded_file($_files["file"]["tmp_name"],       "upload/" . $_files["file"]["name"]);       echo "stored in: " . "upload/" . $_files["file"]["name"];       }     }      }     else     {     echo "invalid file";        }        ?> 

i have problem, if use code upload file invalid file response.

edit:

<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> 

this code uploads images.

you cannot upload same files uploaded.

you cannot upload files more 20kb.

make sure have directory named 'upload' in source folder


Comments