title: Is there a safe and reliable way to check if a file is a text file if mime type detecting fails?
body: <p>I have a website that works with text files that users upload, to make sure that they are actually text files i check the mime type in PHP like this:</p>
  
  <pre><code>$finfo = finfo_open(FILEINFO_MIME_TYPE);
  $mimeType = finfo_file($finfo, $filepath);
  finfo_close($finfo);
  </code></pre>
  
  <p>Which works fine most of the time. The problem is that sometimes files are uploaded that contain a few control characters (non-printable characters like nul or stx). Trying to get the mime type of these files always returns application/octet-stream. For example, a textfile i have that is 560 lines long, contains one nul character on line 12, and therefor gets indentified as application/octet-stream</p>
  
  <p>Is there any safe and reliable way to check if an uploaded file is a text file when detecting the mime type doesn't work?</p>