Check if uploaded file is CSV Format or not in php

$csv_mimetypes = array(
    ‘text/csv’,
    ‘text/plain’,
    ‘application/csv’,
    ‘text/comma-separated-values’,
    ‘application/excel’,
    ‘application/vnd.ms-excel’,
    ‘application/vnd.msexcel’,
    ‘text/anytext’,
    ‘application/octet-stream’,
    ‘application/txt’,
);
if (in_array($_FILES[‘upload’][‘type’], $csv_mimetypes)) {
    // possible CSV file
    // could also check for file content at this point
}
Please follow and like us:

Check if file is csv type

//File type Checking:
$mimes = array(‘application/vnd.ms-excel’,’text/plain’,’text/csv’,’text/tsv’);
if(!in_array($_FILES[‘sf_admin_file’][‘type’],$mimes))
{
            $this->form_validation->set_rules(‘sf_admin_file’, ‘Document’, ‘required’);
}
Please follow and like us: