How to check is upload file is CSV or XLS

大城市里の小女人 提交于 2019-12-25 04:38:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!