You are here

function imce_validate_all in IMCE 6

Same name and namespace in other branches
  1. 6.2 inc/imce.page.inc \imce_validate_all()
  2. 7 inc/imce.page.inc \imce_validate_all()

Validate uploaded file.

File

inc/page.inc, line 561

Code

function imce_validate_all(&$file, $imce) {

  //fix FILE_EXISTS_ERROR bug. core bug #54223.
  if (!$file->destination && variable_get('imce_settings_replace', FILE_EXISTS_RENAME) == FILE_EXISTS_ERROR) {
    return array(
      t('File browser is set to reject the upload of existing files.'),
    );
  }

  //validate image resolution only if filesize validation passes.

  //because user might have uploaded a very big image

  //and scaling it may exploit system memory.
  $errors = imce_validate_filesize($file, $imce['filesize']);
  if (empty($errors) && imce_image_info($file->filepath)) {

    //image resolution validation
    $errors = array_merge($errors, file_validate_image_resolution($file, $imce['dimensions']));
  }
  if ($imce['quota']) {

    //directory quota validation
    $errors = array_merge($errors, imce_validate_quota($file, $imce['quota'], $imce['dirsize']));
  }
  if ($imce['extensions'] != '*' && !preg_match('/\\.(' . str_replace(' ', '|', $imce['extensions']) . ')$/i', $file->filename)) {
    $errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array(
      '%files-allowed' => $imce['extensions'],
    ));
  }
  if (empty($errors) && $imce['tuquota']) {

    //total user quota validation. check everything before hitting the DB
    $errors = array_merge($errors, imce_validate_quota($file, $imce['tuquota'], file_space_used($imce['uid']), 1));
  }
  return $errors;
}