title: php HTTP File Upload variables are not always readable
body: <p>In PHP (Version 5.4.39-0+deb7u2) I upload files.
  This went smooth for about 3 years, until today.</p>
  
  <p>After hours of testing I noticed that the <strong>$_FILES['Filedata']['name']</strong> array is not readable when:</p>
  
  <ul>
  <li>the filename is written by a Mac OSX system when the PATHINFO_EXTENSION is '<strong>.jpg</strong>'</li>
  <li>files written as '.JPG' have no problems.</li>
  <li>when the filename contains '<strong>-_</strong>' (eg 20151126-_HG634163.JPG)</li>
  <li>files written on PC containing .jpg, .JPG, -_, ... are working perfect</li>
  </ul>
  
  <p>Below the code that worked perfect until this morning. There were no server-changes.
  Both Chrome and Safari gave the same results.
  The <strong><em>$this->file_name</em></strong> variable is stored in a DB to prevent doubles.</p>
  
  <pre><code>        if (!empty($_FILES)) {
          $tempFile = $_FILES['Filedata']['tmp_name'];
          $ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION);
          $this-&gt;file_name = $_FILES['Filedata']['name'];
          $fileTypes = array('jpg','JPG','jpeg'); // File extensions
          $this-&gt;new_filename = $_POST['i']."_".date(YmdHis).$i."_".sha1($this-&gt;file)."_".rand(0, 1000)."_".rand(0, 1000).".JPG";
          $this-&gt;new_file = $this-&gt;targetFile."/".$this-&gt;new_filename;
  
          if (in_array($ext,$fileTypes)) {
          move_uploaded_file($tempFile,$this-&gt;new_file);
          } else {
          $this-&gt;upload_error = 1;
          }
          }
  </code></pre>