| Versionen | |
|---|---|
| drupal6 – drupal7 | file_validate_extensions($file, $extensions) |
Check that the filename ends with an allowed extension. This check is not enforced for the user #1.
$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.
includes/
<?php
function file_validate_extensions($file, $extensions) {
global $user;
$errors = array();
// Bypass validation for uid = 1.
if ($user->uid != 1) {
$regex = '/\.(' . ereg_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;
}
?>
Kommentare
Kommentar hinzufügen