Is there anyway to specify which files types can be uploaded using this code:
<input type="file" id="fighter2_upload" name="fighter2_upload" size=48>
I only want to be able to upload jpg / jpeg files.
Any ideas?
Thanks
Is there anyway to specify which files types can be uploaded using this code:
<input type="file" id="fighter2_upload" name="fighter2_upload" size=48>
I only want to be able to upload jpg / jpeg files.
Any ideas?
Thanks
You cant achive this with just HTML - you could use Javascript to check the file type but this can be disabled by the user and bypassed - see this example http://www.codestore.net/store.nsf/unid/DOMM-4Q8H9E
Other wise you need somthing like PHP to check the file type on the server side
UPDATE: Also worth noting - This is not entirely foolproof as people can easily change the extension of a file before uploading it, or do some other trickery, as in the case of the "LoveBug" virus.
You can look at the extension with JavaScript, but people can disable that.
E.g.
if ( ! document.getElementById('upload-file').value.match(/\.jpe?g$/)) {
alert('JPEG files only');
}
You can use the accept attribute but it is not "accepted" on all browsers.
You can refer to this post: File input 'accept' attribute - is it useful?
You will need to do server side and JavaScript validation.
What you could do is capture the JavaScript change event of the file input and check the file type there...this will be your first chance of letting the user know if the file type is accepted or not.
You can check this inside a validation function of the form.
if((document.form1.upload.value.lastIndexOf(".jpg")==-1) {
alert("Please upload only .jpg extention file");
return false;
}