You are here

function mimedetect_fileupload_file_validate in MimeDetect 7

Same name and namespace in other branches
  1. 8 mimedetect_fileupload/mimedetect_fileupload.module \mimedetect_fileupload_file_validate()

Implements hook_file_validate().

File

mimedetect_fileupload/mimedetect_fileupload.module, line 14
MimeDetect file upload validation sub-module.

Code

function mimedetect_fileupload_file_validate($file) {
  $errors = array();
  $detected_mime = mimedetect_mime($file);
  if ($file->filemime != $detected_mime) {
    $extension = pathinfo($file->filename, PATHINFO_EXTENSION);
    $errors[] = t('Detected file MIME type (@type) does not match the filename extension (@extension).', array(
      '@type' => $detected_mime,
      '@extension' => $extension,
    ));
  }
  return $errors;
}