How to check the CSV or XLS download file

I upload a CSV or XLS file and import the contents of this file into a database. There are two separate CSV file reading method and XLS ( readCSV()and readXLS()). when i upload a csv or xls file that gave me the same file type

if(file_type($my_file) =='CSV'){
  readCSV();
}else{
  readXLS();
}

How can I write the file_type () function to get a separate result for CSV and XLS files

0
source share
2 answers

Try the following:

$extension = end(explode('.', $_FILES['image']['name']));

if($extension == 'cvs' || $extension == 'xls')
{
   echo 'ok';
}
else
{
   echo 'error';
}
  • thank

+1
source
<?php
$chunks = basename($your_file_path).explode('.');
if(strtolower($chunks[count($chunks)-1]) == 'csv'){
  //csv
}else{
 //whatever
}
0
source

Source: https://habr.com/ru/post/1539558/


All Articles