Stop people from uploading GIF and JPG files in a group forum

Asked By 30 points N/A Posted on -
qa-featured

Hi!

I have this closed group forum and I want to stop people from uploading gif and jpg files since I prefer using png files. Any recommendations?

SHARE
Answered By 5 points N/A #137050

Stop people from uploading GIF and JPG files in a group forum

qa-featured

This requires programming knowledge on HTML and JavaScript to restrict the file type from submitting. Below is a sample Code written using JavaScript and HTML.

JavaScript Code.

<scripttype="text/javascript">

    function CheckFileType(obj) {

        var filePath = obj.value;

        //Get the file extension from file path

        var FileExtension = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();

        //Check the extension for invalid formats

        if (FileExtension != 'gif' || FileExtension != 'jpg') {

            alert('Only png files are allowed');

        } else {

            document.getElementById('form1').submit();

        }

    }

</script>

HTML Code.

Assuming that you are using file control to submit files to the server below code is written. You can modify the code according to your requirement.


  <form method="post" onsubmit="returnCheckFileType(this.value);">

    <inputtype="file" id="fileControl" name="fileControl"/>
 
</form>
 

 

Related Questions