chrisml's avatar

How to upload images and videos with one file input that has different max size limits?

I will elaborate...

I'm trying to use one file input to upload both images and videos. I want to have a 5mb limit on images and a 15mb limit on videos. Basically the same way you upload media to a Tweet on Twitter. Is this at all possible with Laravel's validation?

0 likes
5 replies
simondavies's avatar

I use http://www.dropzonejs.com/ to upload multiple files, then a php class behind it to do several things like move, rename etc.

But also you can validate extensions etc and within here check if its an image / video then compare the size with its type from there, then return the results.

Laravel has a good file class etc that helps alot.

chrisml's avatar

@simondavies Thanks for the reply.

But also you can validate extensions etc and within here check if its an image / video then compare the size with its type from there, then return the results.

This is what I'm stuck with. I'm wondering if I validate the input with mime types for images and video i.e. 'file' => 'mimes:jpeg,png,bmp,gif,svg,mp4,qt' how would I then check the file size. Surely I'd have to write another validate method using Validator::extend() but that's where I'm completely lost, there isn't much documentation regarding extend. I need to know how to return errors properly, etc.

chrisml's avatar

Bumping this. Appreciate any kind of suggestions!

Thuo's avatar

hey @chrisml did you ever resolve this? working on something similar

Please or to participate in this conversation.