title: How to check for the correct file extension in PHP?
body: <p>So basically, I am simply just trying to check for the correct file extension on a file that is being uploaded.</p>
  
  <p>I know, this question has been answered on here a few times before, although I keep getting the same error and there is no solution or suggestions out there to why this is happening.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$file = fopen($_FILES['upload_csv']['tmp_name'], 'r');
  $ext = pathinfo($file, PATHINFO_EXTENSION);
  
  if($ext != "csv")
  {
      $errors[] = "Sorry, but only CSV files are supported";
  }
  </code></pre>
  
  <p>Here is my error:</p>
  
  <pre><code>Warning: pathinfo() expects parameter 1 to be string
  </code></pre>
  
  <p>I have tried around 3 other alternatives now, all using <code>pathinfo()</code>. Although, the exact same error is still shown.</p>
  
  <p>Does anyone have any suggestions to why this is happening?</p>