0
アップロード時にXLSXファイルの正しいMIMEタイプを検出しようとしていますが、これまでのところ何も動作していないようです。PHP XLSX間違ったMIMEタイプが検出されました
$allowed_mimes = [
'pdf' => 'application/pdf',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'xls' => 'application/vnd.ms-excel',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'rtf' => 'application/rtf',
'odt' => 'application/vnd.oasis.opendocument.text',
];
$finfo = new finfo(FILEINFO_MIME_TYPE);
$is_allowed = array_search($finfo->file($attachment['tmp_name']), $allowed_mimes, true);
if (false === $is_allowed) {
return [
'error' => true,
'title' => 'File format not supported',
'message' => 'This file format is not supported yet. Format: ' . $finfo->file($attachment['tmp_name']),
];
}
私は.htaccess
ファイルにAddType
をすでに使用している:これはどちらか私のために動作するようには思えない
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx
。私はApacheを使用しているVPS(Ubuntu)上で、/etc/mime.types
ファイルとapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
が存在することを確認しました。また/usr/share/mime/application/vnd.openxmlformats-officedocument.wordprocessingml.document.xml
ファイルが存在します。私は問題が何であるか分かりません。