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

BourneShady
  • 955
  • 2
  • 17
  • 36

2 Answers2

2

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

Community
  • 1
  • 1
elfif
  • 1,837
  • 17
  • 23
  • A good answer. I'll back it up by saying that the issue @BourneShady has is mostly client-side dependent. If you're not getting the results you want, but the code looks correct, check to see if what you want to do is supported with caniuse http://caniuse.com/#feat=input-file-accept – Justin Origin Broadband Jun 09 '16 at 09:23
1
{{ 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

bhavinjr
  • 1,663
  • 13
  • 19