function file_validate_name_length

Checks for files with names longer than can be stored in the database.

Parameters

Drupal\file\File $file: A file entity.

Return value

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

1 call to file_validate_name_length()
ValidatorTest::testFileValidateNameLength in drupal/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php
This will ensure the filename length is valid.

File

drupal/core/modules/file/file.module, line 342
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_validate_name_length(File $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) > 240) {
    $errors[] = t("The file's name exceeds the 240 characters limit. Please rename the file and try again.");
  }
  return $errors;
}