2 years ago

Uploaded video is saved in directory with file name instead of in root folder

Posted 2 years ago by roemer

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:


It should be:


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);

            $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())

Can anyone tell what's going wrong? Thanks

Please sign in or create an account to participate in this conversation.