Rewrite of getExtension
This commit is contained in:
parent
54b7fc57c0
commit
e93564c3e0
@ -278,7 +278,7 @@ final class Album {
|
||||
if (!@is_readable($photo->url)) continue;
|
||||
|
||||
// Get extension of image
|
||||
$extension = getExtension($photo->url);
|
||||
$extension = getExtension($photo->url, true);
|
||||
|
||||
// Set title for photo
|
||||
$zipFileName = $zipTitle . '/' . $photo->title . $extension;
|
||||
|
@ -50,7 +50,7 @@ final class Import {
|
||||
// This prevents us from downloading invalid photos.
|
||||
|
||||
// Verify extension
|
||||
$extension = getExtension($url);
|
||||
$extension = getExtension($url, true);
|
||||
if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
|
||||
$error = true;
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Photo format not supported (' . $url . ')');
|
||||
|
@ -123,7 +123,7 @@ final class Photo {
|
||||
}
|
||||
|
||||
// Verify extension
|
||||
$extension = getExtension($file['name']);
|
||||
$extension = getExtension($file['name'], false);
|
||||
if (!in_array(strtolower($extension), self::$validExtensions, true)) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Photo format not supported');
|
||||
if ($returnOnError===true) return false;
|
||||
@ -844,8 +844,8 @@ final class Photo {
|
||||
}
|
||||
|
||||
// Get extension
|
||||
$extension = getExtension($photo->url);
|
||||
if ($extension===false) {
|
||||
$extension = getExtension($photo->url, true);
|
||||
if (empty($extension)) {
|
||||
Log::error(Database::get(), __METHOD__, __LINE__, 'Invalid photo extension');
|
||||
return false;
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
<?php
|
||||
|
||||
function getExtension($filename) {
|
||||
# Returns the extension of the filename (path or URI) or an empty string
|
||||
function getExtension($filename, $isURI = false) {
|
||||
|
||||
$extension = strpos($filename, '.') !== false
|
||||
? strrchr($filename, '.')
|
||||
: '';
|
||||
# If $filename is an URI, get only the path component
|
||||
if ($isURI)
|
||||
$filename = parse_url($filename, PHP_URL_PATH);
|
||||
|
||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
if (!empty($extension))
|
||||
$extension = '.' . $extension;
|
||||
|
||||
return $extension;
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user