8.5.x file.module file_validate_name_length(FileInterface $file)
8.0.x file.module file_validate_name_length(FileInterface $file)
8.1.x file.module file_validate_name_length(FileInterface $file)
8.2.x file.module file_validate_name_length(FileInterface $file)
8.3.x file.module file_validate_name_length(FileInterface $file)
8.4.x file.module file_validate_name_length(FileInterface $file)
8.6.x file.module file_validate_name_length(FileInterface $file)
6.x file.inc file_validate_name_length($file)
7.x file.inc file_validate_name_length(stdClass $file)

Check for files with names longer than we can store in the database.

Parameters

$file: A Drupal file object.

Return value

An array. If the file name is too long, it will contain an error message.

Related topics

File

includes/file.inc, line 720
API for handling file uploads and server file management.

Code

function file_validate_name_length($file) {
  $errors = array();
  if (strlen($file->filename) > 255) {
    $errors[] = t('Its name exceeds the 255 characters limit. Please rename the file and try again.');
  }
  return $errors;
}