title: PHP File upload form not working
body: <p>I've used this code in another site I've made and it works absolutely fine so I'm really confused as to why this isn't working properly. The only things I have changed are the directories for the file to be moved to, but the files never get uploaded. I've triple checked everything and it all seems fine. The code all executes without errors and all of the info gets entered into the database correctly, the only problem is the file not uploading. I'm going mad trying to get this to work! please help!</p>
  
  <p>HTML FORM:</p>
  
  <pre><code>&lt;p&gt;
  &lt;h2&gt;Add News&lt;/h2&gt;&lt;br /&gt;
  REQUIRED *&lt;br /&gt;&lt;br /&gt;
  &lt;form enctype="multipart/form-data" action='addnews2.php' method='post' onsubmit="chose.value = uploadForm()" name="newsform"&gt;
  &lt;p&gt;Headline:  *
  &lt;br&gt;
  &lt;input name="title" type="text" size="75"&gt;
  &lt;br /&gt;
  &lt;br/&gt;
  
    News: *&lt;br&gt;
  &lt;textarea name="text" cols="75" rows="10" width="200"&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;
  Image File:   
  &lt;br&gt;
  &lt;input type="file" name="filetoupload" id="filetoupload"&gt;&lt;br/&gt;&lt;br /&gt;
  
    &lt;input type="submit" name="choose" value="Submit" /&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>Processing Page:</p>
  
  <pre><code>$date=date("l F d, Y");
  
  $title=stripslashes($_POST['title']);
  $text=stripslashes($_POST['text']);
  
  if (($_FILES["filetoupload"]["type"] == "image/gif")
  || ($_FILES["filetoupload"]["type"] == "image/jpeg")
  || ($_FILES["filetoupload"]["type"] == "image/pjpeg")
  || ($_FILES["filetoupload"]["type"] == "image/png")
  || ($_FILES["filetoupload"]["type"] == "image/jpg"))
    {
    if ($_FILES["filetoupload"]["error"] &gt; 0)
      {
      echo "Return Code: " . $_FILES["filetoupload"]["error"] . "&lt;br /&gt;";
      }
      else
        {
              if (file_exists("images/news/" . $_FILES["filetoupload"]["name"]))
        {
        echo $_FILES["filetoupload"]["name"] . " already exists. ";
        }
        move_uploaded_file($_FILES["filetoupload"]["tmp_name"],
        "images/news/" . $_FILES["filetoupload"]["name"]);
        }
      }
  
  
  
  $image = "images/news/".$_FILES['filetoupload']['name'];
  
  
  if($title==""||$text==""){
      die("You need to fill in all details");
  }
  
  
  connect_to_db();
  $query="insert into news (date, title, text, image) values ('".$date."','".mysql_real_escape_string($title)."','".mysql_real_escape_string($text)."','".$image."')";
  $result=mysql_query($query);
  
  if(mysql_affected_rows()==1){
  header("Location:index.php?page=Admin&amp;news=added");
  }
  else{
      die("there was a problem");
  }
  mysql_close();
  </code></pre>