Hi I want that the input file accept only one file.
I mean when I try select file for upload only one file can be select
I know that we can use multiple like this
<input type="file" name="img" multiple>
but can we use something like this?
<input type="file" name="img" multiple = false>
this is my code
<form action="/Panel/Uploader" method="post" enctype="multipart/form-data" class="dropzone" id="dropzoneForm">
<div class="fallback">
<input name="file" type="file" accept="image/jpeg, image/png, image/gif" />
<input type="submit" value="Upload" />
</div>
</form>
To allow multiple file uploads in HTML forms, use the multiple attributes. The multiple attributes work with email and file input types. For limiting maximum items on multiple inputs, use JavaScript. Through this, limit the number of files to be uploaded.
Here is the codepen link.
Don't use multiple
attribute.
<input type="file" name="img">
We can see that we can't select more than one file.
Tested on Mozilla and chrome.
You can even restrict using js
$(function(){
$("input[type='submit']").on('click', () => {
var $fileUpload = $("input[type='file']");
if (parseInt($fileUpload.get(0).files.length)>1){
// handle here
return false;
}
});
});
You can't like this:
<input type="file" name="img" multiple = false>
But if you wan't only to select one file you can do something like this:
<input type="file" name="img">
You just have to remove "multiple".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With