title: Undefined Index in File upload php script
body: <p>I am trying to create a page for a site that I am working on, which allows users to upload a logo image for a vendor while adding other information about that vendor to a database.  The filename gets stored in a mysql database and the image is supposed to be uploaded to ./graphics to used in another place on the site. </p>
  
  <p>The mysql part is working perfectly at this point, but I can't seem to get the image to upload to ./graphics.</p>
  
  <p>I checked the Apache error log and found the following...</p>
  
  <pre><code>[Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 72, referer: http://localhost/labconnect2/addvendor.php
  [Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 74, referer: http://localhost/labconnect2/addvendor.php
  [Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 75, referer: http://localhost/labconnect2/addvendor.php
  [Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 76, referer: http://localhost/labconnect2/addvendor.php
  [Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 77, referer: http://localhost/labconnect2/addvendor.php
  [Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 78, referer: http://localhost/labconnect2/addvendor.php
  [Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 79, referer: http://localhost/labconnect2/addvendor.php
  [Fri Aug 09 07:18:50 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined index: VendorLogo in /var/www/labconnect2/addvendor.php on line 117, referer: http://localhost/labconnect2/addvendor.php
  </code></pre>
  
  <p>So I checked and double checked my form code and verified the name attribute in the form tag. I also checked to make sure the the $_FILES was referencing that name properly, and it is (as far as I can tell).</p>
  
  <p>I did some research and found that this could be a result of the max upload size and max post size parameters in the php.ini, so I double checked that and they are both set to 2m.</p>
  
  <p>I am sure that this "undefined index" error is the reason that the file is not uploading, but I cannot seem to find what is wrong with my code.</p>
  
  <pre><code>&lt;!DOCTYPE&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;title&gt;Add New vendor&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="./css/addnew.css"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;div id="box"&gt;
          &lt;div id="exit"&gt;
              &lt;h2&gt;&lt;a href="./index.php"&gt;X&lt;/a&gt;&lt;/h2&gt;        
          &lt;/div&gt;
  
          &lt;div id="form"&gt;
  
              &lt;form name="new_entry" method="post" enctype="multipart/form-data"&gt;
                  Name 
                  &lt;br&gt;
                  &lt;input type="text" name="vendor"&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  Support Website for Vendor
                  &lt;br&gt;
                  &lt;input type="text" name="SupportSite"&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  Phone Number for Support
                  &lt;br&gt;
                  &lt;input type="tel" name="SupportNum"&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  Main Website for Vendor
                  &lt;br&gt;
                  &lt;input type="text" name="MainSite"&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  Notes
                  &lt;br&gt;
                  &lt;textarea rows="4" cols="50" maxlength="255" wrap="hard" name="notes"&gt;&lt;/textarea&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  &lt;p&gt;Upload Logo:    &lt;input type="file" name="VendorLogo"&gt; &lt;/p&gt;
                  &lt;p&gt;&lt;em&gt;PNG images with transparent backgrounds are best.&lt;/em&gt;&lt;/p&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  &lt;input type="submit"&gt;
  
  
              &lt;/form&gt;
  
          &lt;/div&gt;
  
      &lt;/div&gt;
  
      &lt;?php
  
          $con=mysqli_connect('localhost','ssctechlab','paracon','ssctechlab');
  
          //check connection
          if(mysqli_connect_errno()) {
              echo "failed to connect to MySQL Server: " . mysqli_connect_error();
          };
  
          //echo 'Connected... ' . mysqli_get_host_info($link) . "\n";
  
  
          //Image Upload
                      $allowedExts = array("gif", "jpeg", "jpg", "png");
              $temp = explode(".", $_FILES["VendorLogo"]["name"]);
              $extension = end($temp);
              if ((($_FILES["VendorLogo"]["type"] == "image/gif")
              || ($_FILES["VendorLogo"]["type"] == "image/jpeg")
              || ($_FILES["VendorLogo"]["type"] == "image/jpg")
              || ($_FILES["VendorLogo"]["type"] == "image/pjpeg")
              || ($_FILES["VendorLogo"]["type"] == "image/x-png")
              || ($_FILES["VendorLogo"]["type"] == "image/png"))
              &amp;&amp; ($_FILES["VendorLogo"]["size"] &lt; 20000)
              &amp;&amp; in_array($extension, $allowedExts))
                {
                if ($_FILES["file"]["error"] &gt; 0)
                  {
                  echo "Return Code: " . $_FILES["VendorLogo"]["error"] . "&lt;br&gt;";
                  }
                else
                  {
                  echo "Upload: " . $_FILES["VendorLogo"]["name"] . "&lt;br&gt;";
                  echo "Type: " . $_FILES["VendorLogo"]["type"] . "&lt;br&gt;";
                  echo "Size: " . ($_FILES["VendorLogo"]["size"] / 1024) . " kB&lt;br&gt;";
                  echo "Temp file: " . $_FILES["VendorLogo"]["tmp_name"] . "&lt;br&gt;";
  
                  if (file_exists("upload/" . $_FILES["VendorLogo"]["name"]))
                   {
                   echo $_FILES["VendorLogo"]["name"] . " already exists. ";
                   }
                  else
                   {
                   move_uploaded_file($_FILES["VendorLogo"]["tmp_name"],
                   "upload/" . $_FILES["VendorLogo"]["name"]);
                   echo "Stored in: " . "graphics/" . $_FILES["VendorLogo"]["name"];
                   }
                  }
                }
              else
                {
                echo "Invalid file";
                }
  
      //Insert info into VendorInfo Table
          $vendor = $_POST["vendor"];
          $SupportSite = $_POST["SupportSite"];
          $SupportNum = $_POST["SupportNum"];
          $MainSite = $_POST["MainSite"];
          $notes = $_POST["notes"];
          $VendorLogo = ($_FILES["VendorLogo"]["name"]);
  
  
  
          mysqli_query($con,"INSERT INTO VendorInfo VALUES('','$VendorLogo','$vendor','$SupportSite','$SupportNum','$MainSite','$notes')");
  
  
          mysqli_close($con);
  
          //header('Location: ./index.php')
  
      ?&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>By the way, this is based code I got from w3schools.com.  I am still a total noob so go easy on me please.</p>