1

I created an excel upload button in my HTML file.

        <tr>
            <td><label for="id_excel">Excel: </label></td>
            <td class="fileUpload btn">
                <input type="file" name="excel" id="id_excel" class="upload" />
            </td>
        </tr>

Since I created this button to get Excel files, I want to prevent users to upload something else (for example docx or pdf). How can I limit the user to upload only Excel file type?

Thanks.

1
  • Is your issue resolved? please vote up arrow if so. Thanks :) Commented Oct 3, 2015 at 15:56

1 Answer 1

1

Just add this in the It works fine for me, hope this will resolve your issue.

<script>
var fl = document.getElementById('id_excel');

fl.onchange = function(e){ 
    var ext = this.value.match(/\.(.+)$/)[1];
    switch(ext)
    {
        case 'xls':
        case 'xlsx':
            alert('allowed');
            break;
        default:
            alert('not allowed');
            this.value='';
    }
};
    </script>
Sign up to request clarification or add additional context in comments.

1 Comment

How do I use the said upload button to save the chosen file to the database?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.