public static function errorCapacityover($files) {
$error = false;
foreach(array('rirekisho','shokumukeirekisho') as $val) {
if(empty($files[$val]['name']) ){
continue;
}
$filesize = filesize($files[$val]['tmp_name']);
if($filesize > 10485760){
$error = true;
}
}
return $error;
}
public static function errorExtensions($files) {
$error = false;
// ファイル拡張子一覧を取得
$allowed_extensions = Form::fileExtension();
// MIMEタイプ一覧を取得
$allowed_mime_types = Form::fileMimeTypes();
foreach(array('rirekisho','shokumukeirekisho') as $val) {
if(empty($files[$val]['name']) ){
continue;
}
// 拡張子を取得
$file_name = $files[$val]['name'];
$file_extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
// MIMEタイプを取得
$tmp_name = $files[$val]['tmp_name'];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $tmp_name);
finfo_close($finfo);
// 拡張子とMIMEタイプの両方をチェック
if (in_array($file_extension, $allowed_extensions) && in_array($mime_type, $allowed_mime_types)) {
} else {
$error = true;
}
}
return $error;
}
// ファイル拡張子
public static function fileExtension(){
return [
// 画像系ファイル
'jpg', 'jpeg', 'jp2', 'png', 'heic', 'heif', 'gif', 'webp', 'bmp', 'tiff', 'tif',
// PDFファイル
'pdf',
// Word系ファイル
'doc', 'docm', 'docx', 'dot', 'dotm', 'dotx',
// Excel系ファイル
'xls', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx',
// PowerPoint系ファイル
'ppt', 'pptm', 'pptx', 'pot', 'potm', 'potx', 'pps', 'ppsm', 'ppsx',
// Outlook系ファイル
'pst', 'ost', 'msg', 'olm', 'eml',
// テキスト系ファイル
'txt', 'csv', 'md',
// 圧縮ファイル
'zip', 'gz', 'rar', 'tar', '7z', 'cab', 'lzh',
// OpenDocument系ファイル
'odt', 'ott', 'ods', 'ots', 'odp', 'otp', 'odg',
// 動画系ファイル
'mp4', 'mkv',
// Adobe系ファイル
'psd', 'ai',
// Apple系ファイル
'numbers', 'pages', 'webarchive'
];
}
// MIMEタイプ
public static function fileMimeTypes(){
return [
// 画像系ファイル
'image/jpeg',
'image/jp2',
'image/png',
'image/heic',
'image/heif',
'image/gif',
'image/webp',
'image/bmp',
'image/x-ms-bmp',
'image/tiff',
// PDFファイル
'application/pdf',
// Word系ファイル
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.macroEnabled',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template.macroEnabled',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
// Excel系ファイル
'application/excel',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.macroEnabled',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template.macroEnabled',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
// PowerPoint系ファイル
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint.presentation.macroenabled.12',
'application/vnd.ms-powerpoint.template.macroenabled.12',
'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
// Outlook系ファイル
'application/vnd.ms-outlook',
'application/vnd.ms.outlook',
'message/rfc822',
// テキスト系ファイル
'text/plain',
'text/csv',
'text/markdown',
'application/csv',
// 圧縮ファイル
'application/zip',
'application/gzip',
'application/x-gzip',
'application/x-compressed',
'application/vnd.rar',
'application/x-rar-compressed',
'application/x-rar',
'application/rar',
'application/x-tar',
'application/x-7z-compressed',
'application/vnd.ms-cab-compressed',
'application/x-lzh',
'application/x-lzh-compressed',
// OpenDocument系ファイル
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.text-template',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.spreadsheet-template',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.oasis.opendocument.presentation-template',
'application/vnd.oasis.opendocument.graphics',
// 動画系ファイル
'video/mp4',
'video/x-matroska',
// Adobe系ファイル
'application/postscript',
'application/illustrator',
'image/vnd.adobe.photoshop',
// Apple系ファイル
'application/vnd.apple.numbers',
'application/vnd.apple.pages',
'application/x-webarchive'
];
}