diff --git a/lib/media/imagefile.php b/lib/media/imagefile.php index 1818c76900..cf425cbae8 100644 --- a/lib/media/imagefile.php +++ b/lib/media/imagefile.php @@ -256,13 +256,19 @@ class ImageFile extends MediaFile * * @param string $url Remote image URL * @param Profile|null $scoped + * @param string|null $name * @return ImageFile * @throws ClientException + * @throws FileNotFoundException + * @throws InvalidFilenameException + * @throws NoResultException * @throws ServerException + * @throws UnsupportedMediaException + * @throws UseFileAsThumbnailException */ - public static function fromUrl(string $url, ?Profile $scoped = null): self + public static function fromUrl(string $url, ?Profile $scoped = null, ?string $name = null): self { - $mediafile = parent::fromUrl($url, $scoped); + $mediafile = parent::fromUrl($url, $scoped, $name); if ($mediafile instanceof self) { return $mediafile; } else { diff --git a/lib/media/mediafile.php b/lib/media/mediafile.php index e0ece91d72..31179db08f 100644 --- a/lib/media/mediafile.php +++ b/lib/media/mediafile.php @@ -445,10 +445,17 @@ class MediaFile * * @param string $url Remote media URL * @param Profile|null $scoped + * @param string|null $name * @return ImageFile|MediaFile + * @throws ClientException + * @throws FileNotFoundException + * @throws InvalidFilenameException + * @throws NoResultException * @throws ServerException + * @throws UnsupportedMediaException + * @throws UseFileAsThumbnailException */ - public static function fromUrl(string $url, ?Profile $scoped = null) + public static function fromUrl(string $url, ?Profile $scoped = null, ?string $name = null) { if (!common_valid_http_url($url)) { // TRANS: Server exception. %s is a URL. @@ -478,10 +485,10 @@ class MediaFile File::respectsQuota($scoped, filesize($temp_filename)); } - $mimetype = self::getUploadedMimeType($temp_filename); + $mimetype = self::getUploadedMimeType($temp_filename, $name ?? false); $media = common_get_mime_media($mimetype); - $basename = basename($temp_filename); + $basename = basename($name ?? $temp_filename); if ($media == 'image') { // Use -1 for the id to avoid adding this temporary file to the DB