Below examples implement the above approach:
Example 1: In this example we upload file having extensions .jpeg/.jpg/.png/.gif only. We store an extension list in a variable and compare each of them with the uploaded file extension. To separate the extension from the uploaded file we will use regular expression and also preview the uploaded file if the uploaded file extension follows the file type.
Example 2: Uploading the file having extensions .doc/.docx/.odt/.pdf/.tex/.txt/.rtf/.wps/.wks/.wpd only. Store the extension list in a variable and compare each of them with the uploaded file extension. To separate the extension from the uploaded file we will use a regular expression.
- File uploading in Node.js
- PHP | Uploading File
- File uploading in React.js
- while and do while Loop in Scala
- Which will be faster while(1) or while(2)?
- Preview an image before uploading using jQuery
- Difference between Downloading and Uploading
- How to trigger onchange event on input type=range while dragging in Firefox ?
- How to reset selected file with input tag file type in Angular 9?
- How to Display Validation Message for Radio Buttons with Inline Images using Bootstrap 4 ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.