I'd like to get the real filename of a file entity.
My code is like this
$filenames = [];
foreach ($entity->$field->referencedEntities() as $image) {
// Filename.
$media = Media::load($image->id());
$fid = $media->field_media_image->target_id;
$file = File::load($fid);
$filenames[] = $file->getFilename();
};
return $filenames;
}
But filename returns the label of the file entity like so. my-image.jpg
and using getFileUri()
returns public://images/my-image_0.jpg
I think because the image has been replaced at some point.
What I would like is just my-image_0.jpg
but I can't seem to find a function to do it.
Thanks