gbowne1 / spmssite

The code for my old business website.
GNU General Public License v3.0
8 stars 31 forks source link

feat: Filetype exclusion in file upload #87

Closed gbowne1 closed 2 years ago

gbowne1 commented 2 years ago

Prerequisites

Describe the Feature Request

Here's the concept..

Under the "accept" of a file input, there can also be a definition of the general type of the files for selection. For example, if you put "image/" under the "accept" attribute, the limitation will cover all the standard file formats (gif, jpeg and so on) for images and not just the type(s) by extensions. In addition, you can combine the pre-defined type(s) and extensions. For example: "image/,.swf". For this example, the limitation will include all standard image files AND all ".swf" files. NOTE: the user can always select "All Files" from the type list in the dialog box...

Before the file is uploaded, you can check the file's extension using Javascript, and prevent the form being submitted if it doesn't match. The name of the file to be uploaded is stored in the "value" field of the form element.

Here's a simple example that only allows files that end in ".gif" to be uploaded:

    function checkFile() {
        var fileElement = document.getElementById("uploadFile");
        var fileExtension = "";
        if (fileElement.value.lastIndexOf(".") > 0) {
            fileExtension = fileElement.value.substring(fileElement.value.lastIndexOf(".") + 1, fileElement.value.length);
        }
        if (fileExtension.toLowerCase() == "gif") {
            return true;
        }
        else {
            alert("You must select a GIF file for upload");
            return false;
        }
    }

Describe the Use Case

Ability to only be able to upload common files used in manufacturing and engineering context like:

.txt .jpg/jpeg .png .webp .docx .doc .dwg .dxf .iges .step

Describe Preferred Solution

No response

Describe Alternatives

Possibly use a filetype upload select in the UI.

Related Code

No response

Additional Information

No response

BrianAndrewOneil commented 2 years ago

Hello, I'd be happy to help you with this issue. Could you assign it to me? Thank you.

BrianAndrewOneil commented 2 years ago

@gbowne1 sorry to bother you, I just realized that I didn't @ you and I'm not sure if that's required for you to see this.

gbowne1 commented 2 years ago

no it's not @BrianAndrewOneil but yes you can help.

gbowne1 commented 2 years ago

This was meant for this file:

https://github.com/gbowne1/spmssite/blob/main/templates/rfq.html

BrianAndrewOneil commented 2 years ago

Okay, thank you, this makes sense. I'll work on this today.

gbowne1 commented 2 years ago

Ok. Great. Thanks! :-) @BrianAndrewOneil

BrianAndrewOneil commented 2 years ago

@gbowne1 I created a pull request for my update, please let me know if you have any questions. Thanks for letting me help with your project!

gbowne1 commented 2 years ago

Great @BrianAndrewOneil

thanks for submitting a PR. I will test it and if it see if it works fine.