Lars-Janssen's avatar

Validating File upload

Hello,

What's a proper way for validating Uploaded files?

Right now I've this for uploading files (that works):

  $file = $request->file('file');
        if(Input::hasfile('file')){
            foreach ($file as $f) {
                $name = time() .$f->getClientOriginalName();
                $userid = Auth::user()->id;
                $f->move('files/'.$userid.'/ticketimages',$name);
                $ticket->image()->create(['path' => '/files/'.$userid.'/ticketimages/'.$name,'name' => $name]);
            }
            //$this->mailer->ticketToAdmin($ticket);
        }

Already followed this video:

https://laracasts.com/lessons/file-uploads-101

But validating files is not covered here.

Some help please.

0 likes
3 replies
d3xt3r's avatar

What do you want to validate it against. couple of options are mime type, dimensions ( for images), file size, etc.

Lars-Janssen's avatar

Yes I would validate it against mime types like: pdf,jpg but also docx. And file size is also important! What's the right way of doing this?

Please or to participate in this conversation.