0

I upload CSV or XLS file and import that file content in to the data base. There is two separate method for read CSV and XLS file read(readCSV() and readXLS()). when i upload CSV or XLS file that gave to me same file type

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

How can i write file_type() function for get separate result for CSV and XLS files

Duleep
  • 569
  • 5
  • 25
  • 49

2 Answers2

0
<?php
$chunks = basename($your_file_path).explode('.');
if(strtolower($chunks[count($chunks)-1]) == 'csv'){
  //csv
}else{
 //whatever
}
coolguy
  • 7,866
  • 9
  • 45
  • 71
  • how about file name don't have `.csv` part – Duleep Oct 17 '13 at 03:39
  • yes of course, sorry for unclear of my question. anyone can upload CSV file name like `abc` if that happen how can i get separate file as CSV? – Duleep Oct 17 '13 at 03:54
0

Try this:

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

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

Flipper
  • 2,589
  • 3
  • 24
  • 32
Anand Solanki
  • 3,419
  • 4
  • 16
  • 27