I am trying to upload an Excel file in my upload directory. It is running when I am not checking the file extension. But when I check the file extension, it displays an invalid file all the time.
My code is given below:
function upload_attendance(){
$config['upload_path'] = './uploads/';
$this->load->library('upload', $config);
$allowedExts = array("xls");
$temp = explode(".",$_FILES["file"]["name"]);
$extension = end($temp);
if(($_FILES["file"]["type"]=="file/xls")&&in_array($extension,$allowedExts)){
if($FILES["file"]["error"]>0){
$data['msg'] = $this->upload->display_errors();
$data['sign'] = 'error_box';
$this->session->set_userdata($data);
redirect('attendance/add_attendance');;
}
else{
echo "Uploaded.";
}
}
else{
$data['msg'] = "Invalid file type.Try to upload a valid file.";
$data['sign'] = 'error_box';
$this->session->set_userdata($data);
redirect('attendance/add_attendance');
}
}
How can I check the file extension before uploading? Could you help me?