title: PHP Upload with file type and size check
body: <p>I need a upload form which other people can use, to hand me in their documents.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form method="post" action="upload.php" enctype="multipart/form-data" id="form"&gt;
  &lt;table&gt;
  &lt;tr&gt;&lt;td&gt;&lt;p&gt;your name:&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input name="name" type="text" size="50" style="height: 30px;"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;p&gt;your mail-adress:&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input name="mail" type="text" size="50" style="height: 30px;"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;p&gt;your document:&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="file" name="file" value="" /&gt;&lt;br /&gt;&lt;h6 style="margin-top: 5px; margin-bottom: 2px;"&gt;max. filesize: 2 MB&lt;br /&gt;allowed filetypes: .doc, .docx, .pdf, .rtf, .odt&lt;/h6&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;br /&gt;
  &lt;input type="submit" value="Send"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  $fehler = "";
  $name = $_POST['name'];
  $mail = $_POST['mail'];
  $file = $_POST['file'];
  $maxsize = "2097152";   /* 2MB in Bytes */
  $allowedext =  array('doc','docx' ,'pdf', 'rtf', 'odt');
  
    if (empty($name)) {
     $fehler .= "&lt;p&gt;&amp;bull; no name given!&lt;/p&gt;" ;
    }
    if (empty($mail)) {
     $error .= "&lt;p&gt;&amp;bull; no e-mail adress given&lt;/p&gt;" ;
    }
    if (empty($file)) {
     $error .= "&lt;p&gt;&amp;bull; choose a file!&lt;/p&gt;" ;
    }
    if (empty($error)) {
     if (!in_array(filetype($file), $allowedext) { /* check filetype */
     $error .= "&lt;p&gt;&amp;bull; filetype is not allowed&lt;/p&gt;" ;
  }
  if (empty($error)) {
     if (filesize($file) &gt; $maxsize) { /* check filesize */
      $error .= "&lt;p&gt;&amp;bull; file is too big&lt;/p&gt;" ;
     }
     if (empty($error)) {
      /* send data via mail */
      echo("your document has been send.");
     }
    }
  }
  echo($error);
  echo ('&lt;p&gt;&lt;a href="../send_article"&gt;back&lt;/a&gt;&lt;/p&gt;');
  ?&gt;
  </code></pre>
  
  <p>I want to check the file type and the size before uploading it. When I upload the upload.php file to my server i just get a white screen without any errors, if i try to use this form.</p>