title: Error uploading files thorugh php script
body: <p>I'm having trouble in creating a php files upload script:</p>
  
  <p><strong>index.php:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;
  &lt;title&gt;File Upload&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form method="post" action="upload_file.php" enctype="multipart/form-data"&gt;
  &lt;label for="file"&gt;&lt;h3&gt;File: &lt;/h3&gt; &lt;/label&gt;
  &lt;input type="file" name="file" id="file" /&gt;&lt;br /&gt;
  &lt;input type="submit" name="Upload" /&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>upload_file.php:</strong></p>
  
  <pre><code>&lt;?php
  $restricted_extensions = array("htm", "html", "php", "asp", "aspx", "js");
  $file_extension = end(explode(".", $_FILES["file"]["name"]));
  
  if ($_FILES["file"]["error"] &gt; 0)
  {
      echo("&lt;h2&gt;An error occured!&lt;/h2&gt;");
      echo("&lt;h2&gt;Return Code: " . $_FILES["file"]["error"] . "&lt;/h2&gt;&lt;br&gt;");
  }
  elseif ($_FILES["file"]["error"] == 0)
  {
      $is_valid_extension = true;
  
  
      foreach ($restricted_extension as $extension =&gt; $value)
      {
          if ($file_extension == $extension)
          {
              $is_valid_extension == false;
          }
  
          if (!$is_valid_extension)
          {
              echo("&lt;h2&gt;The files extension " . $file_extension . " is not allowed!&lt;/h2&gt;");
          }
      }
  }
  else
  {
      echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;";
      echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;";
      echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB&lt;br&gt;";
      echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br&gt;";
  
      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"];
      }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Error Messages:</strong></p>
  
  <p>Notice: Undefined index: file in C:\inetpub\wwwroot\upload_file.php on line 3</p>
  
  <p>Strict Standards: Only variables should be passed by reference in C:\inetpub\wwwroot\upload_file.php on line 3</p>
  
  <p>Notice: Undefined index: file in C:\inetpub\wwwroot\upload_file.php on line 5</p>
  
  <p>Notice: Undefined index: file in C:\inetpub\wwwroot\upload_file.php on line 10</p>
  
  <p>Notice: Undefined variable: restricted_extension in C:\inetpub\wwwroot\upload_file.php on line 15</p>
  
  <p>Warning: Invalid argument supplied for foreach() in C:\inetpub\wwwroot\upload_file.php on line 15</p>