[Solved] How to allow only specific file to allow in HTML

   RSS

1
Topic starter

How to allow only specific file to allow in HTML <input type="file"> attribute

This topic was modified 4 years ago by CodeWithBishal-admin
Topic Tags
1 Answer
1
Topic starter

HTML accept attribute

You can limit the upload file type in HTML <input type="file"> using the [accept] attribute.

For Example, If you want to allow PDF files only, You can specify it by the below code:

<input type="file" accept=".pdf">

Now, with this code, only PDF files can be uploaded.

If you want to to allow multiple file types e.g. [.jpg, .jpeg, .png]. You can achieve this by the below code:

<input type="file" accept=".png, .jpg, .jpeg">

 

And so on you can specify your desired file type to upload.

Also read, How to download files in the desired extension

This post was modified 4 years ago 2 times by CodeWithBishal-admin