You are here

function feeds_imagegrabber_validate_extensions in Feeds Image Grabber 6

Check that the filename ends with an allowed extension. This check is also enforced for the user #1 unlike drupal's default file_validate_extensions.

Parameters

$filename: A string containing the file name to validate

$extensions: A string with a space separated

Return value

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

1 call to feeds_imagegrabber_validate_extensions()
feeds_imagegrabber_is_image in ./feeds_imagegrabber.module
Checks that a file is an image.

File

./feeds_imagegrabber.module, line 627
Grabs image for each feed-item from their respective web pages and stores it in an image field. Requires Feeds module.

Code

function feeds_imagegrabber_validate_extensions($filename, $extensions) {
  $errors = array();
  $regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
  if (!preg_match($regex, $filename)) {
    $errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array(
      '%files-allowed' => $extensions,
    ));
  }
  return $errors;
}