file_validate_extensions($file, $extensions)
drupal/includes/file.inc, line 975
Check that the filename ends with an allowed extension.
@see hook_file_validate()
$file A Drupal file object.
$extensions A string with a space separated
An array. If the file extension is not allowed, it will contain an error message.
| Name | Description |
|---|---|
| File interface | Common file handling functions. |
function file_validate_extensions($file, $extensions) {
global $user;
$errors = array();
$regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
if (!preg_match($regex, $file->filename)) {
$errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $extensions));
}
return $errors;
}