1

Could you tell me (for example, Google could not), if I can set the default file format for file upload.

Currently it allows to upload all files (please refer to the file image *.*), however I would like to limit to a specific file format.

All help is appreciated.

enter image description here

Environment:

NO HTML5

Backend: Struts

FrontEnd: jQuery-1.6.1

File upload plugin uses iframe to upload files.

Jackie Chan
  • 2,654
  • 6
  • 35
  • 70

1 Answers1

1

you can use this

<input type="file"  id="myfile" accept="image/gif, image/jpeg, image/png, image/jpeg" />

but using this. user can anytime change the filter. additionally you should use javascript or jquery to validate.

<script type ="text/javascript">
    var validFiles=["bmp","gif","png","jpg","jpeg"];//array of allowed extensions
        function OnUpload()
        {
          var obj = document.getElementById("myfile");
          var source=obj.value;
          var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
          for (var i=0; i<validFiles.length; i++)
          {
            if (validFiles[i]==ext)
                break;
          }
          if (i>=validFiles.length)
          {
            alert("This not a valid file upload file with an extention of one of the following:\n\n"+validFiles.join(", "));
            return false;
          }
          return true;
         }
    </script>
Raab
  • 34,778
  • 4
  • 50
  • 65