0

I have a module where there is a file upload which accepts any file but it should only process csv files. If there is someother file then it should say invalid file. I have written a code but even when I upload a CSV file it doesnt recognise it as a CSV file. My code is

if($_FILES['file']['type'] != "application/vnd.ms-excel"){
   die("This is not a CSV file.");
}
  • 1
    you can trust neither the mime type nor the file extension provided by the browser. different browsers send different mime types for the same file and the user can just rename it so you can't trust the extension either. You have to use other checks to verify the file after the upload. – Gerald Schneider Apr 02 '14 at 12:32
  • And a CSV is not "application/vnd.ms-excel" either. – deceze Apr 02 '14 at 12:47

1 Answers1

0

Try this

$filename = $_FILES['file']['name'];
$path_parts = pathinfo($filename);
if($path_parts['extension']!='csv'){
   die("This is not a CSV file.");
}
Professor
  • 610
  • 4
  • 20