BourneShady
BourneShady

Reputation: 935

restrict file types in form::file laravel 4.2

so i have this Form::file in my view and i wanted to restrict the file to be uploaded to doc, ppt, pdf, docx, xls, xlsx, txt, etc. so i did my code like this

{{ Form::file('cascUpload' ,
Input::old('cascUpload'), array('id' => 'cascUpload' , 'type' => 'file' , 
'accept' => '.doc , .docx , .pdf , .ppt , .pptx , .xlsx , .xls , .csv , .txt' )) }}

but when clicked, the window opened still displays video , audio and other file types. any ideas on how to properly do this? thanks in advance!

edit i already have a backend checker if the user entered a file type that is not accepted. i just wanted to narrow down the user's choice to a correct file type when he clicked the browse for files. thanks

Upvotes: 2

Views: 4360

Answers (2)

bhavinjr
bhavinjr

Reputation: 1763

{{ Form::file('file',['id' => 'cascUpload', 'accept'=>'.doc , .docx , .pdf , .ppt , .pptx , .xlsx , .xls , .csv , .txt'])}}

try this

Form::File has two parameters name and options

Upvotes: 1

elfif
elfif

Reputation: 1857

You should check that answer : HTML Input="file" Accept Attribute File Type (CSV)

It's the only way to filter the file browser. It it doesn't work last thing you can do is use javascript to check file extension before upload. To do that you will need to use FormData api.

Here is the doc on MDN : https://developer.mozilla.org/en-US/docs/Web/API/FormData

Upvotes: 2

Related Questions