Uploaded video is saved in directory with file name instead of in root folder
Hi, my application contains a media upload feature where users can upload images and videos. I have no trouble saving the images, but I'm running into a problem when saving video. Images get resized using intervention/image, but video's do not. When I try to save a video, a new folder is created with the hashname of the file + the extension, and the video is saved in there, also as the hashname + the extension. An example of this would be as follows:
myproject/storage/app/public/media/{id}/b8e79fb3a719afc566f3cbe0ca47e47b.mp4/b8e79fb3a719afc566f3cbe0ca47e47b.mp4
It should be:
myproject/storage/app/public/media/{id}/b8e79fb3a719afc566f3cbe0ca47e47b.mp4
Here is my code for saving the media:
protected function saveMedia(UploadedFile $media, int $mediaId)
{
$mimeType = $media->getMimeType();
$mediaType = explode('/', $mimeType)[0];
$path = $media->hashName('custom_slide_media/'.$mediaId);
if ($mediaType == 'video')
{
Storage::disk('public')->put($path, $media);
}
else
{
$disk = Storage::disk('public');
$disk->put($path, $this->formatImage($media));
}
return Storage::disk('public')->url($path);
}
protected function formatImage($file)
{
return (string) $this->imageManager->make($file->path())
->fit(900)->encode();
}
Can anyone tell what's going wrong? Thanks
Please or to participate in this conversation.