问题
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
回答1:
<?php
$chunks = basename($your_file_path).explode('.');
if(strtolower($chunks[count($chunks)-1]) == 'csv'){
//csv
}else{
//whatever
}
回答2:
Try this:
$extension = end(explode('.', $_FILES['image']['name']));
if($extension == 'csv' || $extension == 'xls')
{
echo 'ok';
}
else
{
echo 'error';
}
Thanks
来源:https://stackoverflow.com/questions/19417611/how-to-check-is-upload-file-is-csv-or-xls