mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-30 05:24:28 +02:00
Try to detect if an external attachment is an image or not.
Before we assumed that it is a picture in all cases.
This commit is contained in:
parent
1c222ff293
commit
15ba6572df
2 changed files with 14 additions and 3 deletions
|
@ -144,9 +144,17 @@ abstract class Attachment extends AbstractNamedDBElement
|
|||
*/
|
||||
public function isPicture(): bool
|
||||
{
|
||||
//We can not check if an external link is a picture, so just assume this is false
|
||||
if ($this->isExternal()) {
|
||||
return true;
|
||||
//Check if we can extract a file extension from the URL
|
||||
$extension = pathinfo(parse_url($this->path, PHP_URL_PATH) ?? '', PATHINFO_EXTENSION);
|
||||
|
||||
//If no extension is found or it is known picture extension, we assume that this is a picture extension
|
||||
if ($extension === '' || in_array(strtolower($extension), static::PICTURE_EXTS, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Otherwise we assume that the file is not a picture
|
||||
return false;
|
||||
}
|
||||
|
||||
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue