title: How to solve PHP errors : Undefined Index + can't upload file of this type
body: <p>when I try to upload a file to my website I got this [error message in php][1] of Undefined index and &quot;Cannot upload this type of file&quot; even though I try to upload an adequate format (jpg, pdf) as per my code below</p>
  <p><strong>PHP code</strong></p>
  <pre><code>&lt;?php
  if (isset($_POST['submit'])) {
      $file = $_FILES ['file'];
      $fileName = $_FILES ['file'] ['name'];
      $fileTmpName = $_FILES ['file'] ['tmp_name'];
      $fileSize = $_FILES ['file'] ['size'];
      $fileError = $_FILES ['file'] ['error'];
      $fileType = $_FILES ['file'] ['type'];
      $fileExt = explode ('.',$fileName);
      $fileActualExt = strtolower (end($fileExt));
      $allowed = array ('jpg', 'jpeg', 'png', 'pdf', 'doc');
      if (in_array($fileActualExt, $allowed)) {
          if ($fileError === 0) {
              if ($fileSize &lt; 10000000) {
                  $fileNameNew = uniqid ('', true).&quot;.&quot;.$fileActualExt;
                  $fileDestination = 'upload/'.$fileNameNew;
                  move_uploaded_file($fileTmpName, $fileDestination);
                  header (&quot;Location : Contact.html?uploadedsuccessfully&quot;);
              } else {
                  echo &quot;Your file is too big!&quot;;
              }  
          } else {
              echo &quot;There was an error uploading your file!&quot;;
          } 
      } else {
          echo &quot;You cannot upload files of this type!&quot;;
      }
  }
      
  </code></pre>
  <p><strong>HTML code/my form</strong></p>
  <pre><code>&lt;section class= &quot;box3&quot;&gt;
          &lt;h4&gt;Become a contributor&lt;/h4&gt;
          &lt;div class=&quot;lines&quot;&gt;&lt;/div&gt;
          &lt;form class=&quot;contact-form&quot; action=&quot;uploads.php&quot; method= &quot;POST&quot; enctype= &quot;multipart/form-data&quot;&gt; 
              &lt;input type= &quot;file&quot; name=&quot;file&quot; class= &quot;contact-form-text&quot; &gt;
              &lt;button type=&quot;submit&quot; class=&quot;contact-form-btn&quot; name=&quot;submit&quot;&gt;Upload&lt;/button&gt;
          &lt;/form&gt;
      &lt;/section
  </code></pre>
  <blockquote>
  <p><code>Blockquote</code></p>
  </blockquote>
  <p>P.S : I am testing my PHP code locally
  [1]: <a href="https://i.stack.imgur.com/sKylW.jpg" rel="nofollow noreferrer">https://i.stack.imgur.com/sKylW.jpg</a></p>