How to make input type= file Should accept only pdf and xls

后端 未结 9 2114
一生所求
一生所求 2020-12-13 11:26

I used

Now I would like to restrict this by accepting only .pdf and .xls files.

When I click the s

9条回答
  •  一整个雨季
    2020-12-13 12:08

    You could do so by using the attribute accept and adding allowed mime-types to it. But not all browsers do respect that attribute and it could easily be removed via some code inspector. So in either case you need to check the file type on the server side (your second question).

    Example:

    
    

    To your third question "And when I click the files (PDF/XLS) on webpage it automatically should open.":

    You can't achieve that. How a PDF or XLS is opened on the client machine is set by the user.

提交回复
热议问题