All pastes #1597436 Raw Edit

Anonymous

public php v1 · immutable
#1597436 ·published 2009-10-06 10:19 UTC
rendered paste body
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;}