protected function File::getFileName in Feeds 8.3
Extracts the file name from the given url and checks for valid extension.
Parameters
string $url: The URL to get the file name for.
Return value
string The file name.
Throws
\Drupal\feeds\Exception\TargetValidationException In case the file extension is not valid.
1 call to File::getFileName()
- File::getFile in src/
Feeds/ Target/ File.php - Returns a file id given a url.
File
- src/
Feeds/ Target/ File.php, line 238
Class
- File
- Defines a file field mapper.
Namespace
Drupal\feeds\Feeds\TargetCode
protected function getFileName($url) {
$filename = trim(\Drupal::service('file_system')
->basename($url), " \t\n\r\0\v.");
// Remove query string from file name, if it has one.
list($filename) = explode('?', $filename);
$extension = substr($filename, strrpos($filename, '.') + 1);
if (!preg_grep('/' . $extension . '/i', $this->fileExtensions)) {
throw new TargetValidationException($this
->t('The file, %url, failed to save because the extension, %ext, is invalid.', [
'%url' => $url,
'%ext' => $extension,
]));
}
return $filename;
}