file_validate_extensions

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 file_validate_extensions($file, $extensions)

Check that the filename ends with an allowed extension.

see hook_file_validate()

Übergabeparameter

$file A Drupal file object.

$extensions A string with a space separated list of allowed extensions.

Rückgabewert

An array. If the file extension is not allowed, it will contain an error message.

Verwandte Themen

Code

includes/file.inc, line 1082

<?php
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;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen