Я хочу загрузить три файла на свой сервер (.txt, .csv и .xml). .txt и .xml отлично работают с кодом ниже. Только, я не могу загрузить файлы .csv (ни в одном браузере!). Ошибка, которую я получаю: Ошибка! Недоступный тип файла: application/x-csvНе удается загрузить файл .csv (проблема с типом MIME?)
Можно ли исправить это?
Код:
if (isset($_POST['Form']) && isset($_FILES['file'])) {
$types = array('xml', 'csv', 'txt');
$ftypes = array('text/xml', 'application/vnd.ms-excel', 'text/plain');
if (!in_array($_POST['Form']['type'], $types)) {
$errors[] = 'Undefined type';
} elseif (intval($_FILES['file']['size']) == 0) {
$errors[] = 'Zero file size';
} elseif (!in_array($_FILES['file']['type'], $ftypes)) {
$errors[] = 'Unavailable file type: ' . $_FILES['file']['type'];
} else {
$parent_id = intval($_POST['Form']['parent']);
switch ($_POST['Form']['type']) {
case 'xml':
if ($_FILES['file']['type'] != 'text/xml')
$errors[] = "Choosen type and file mime-type doesn't match";
else {
require_once(__DIR__ . '/parsers/xml.php');
}
break;
case 'csv':
if ($_FILES['file']['type'] != 'application/vnd.ms-excel')
$errors[] = "Choosen type and file mime-type doesn't match";
else {
require_once(__DIR__ . '/parsers/csv.php');
}
break;
case 'txt':
if ($_FILES['file']['type'] != 'text/plain')
$errors[] = "Choosen type and file mime-type doesn't match";
else {
require_once(__DIR__ . '/parsers/txt.php');
}
break;
}
}
}
?>