hook_file_validate

Versions
7
hook_file_validate(&$file)

Check that files meet a given criteria.

This hook lets modules perform additional validation on files. They're able to report a failure by returning one or more error messages.

See also

file_validate()

Parameters

$file The file object being validated.

Return value

An array of error messages. If there are no problems with the file return an empty array.

Related topics

Code

modules/system/system.api.php, line 1504

<?php
function hook_file_validate(&$file) {
  $errors = array();

  if (empty($file->filename)) {
    $errors[] = t("The file's name is empty. Please give a name to the file.");
  }
  if (strlen($file->filename) > 255) {
    $errors[] = t("The file's name exceeds the 255 characters limit. Please rename the file and try again.");
  }

  return $errors;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.