I have created a type=file
input element
<input type="file" id="input-id" accept="image/jpg" onchange="verifyFileUpload(event)">
I need to check that the file resolution is aXb
using pure Javascript. How can I do that in the verifyFileUpload(event)
function?
I have created a type=file
input element
<input type="file" id="input-id" accept="image/jpg" onchange="verifyFileUpload(event)">
I need to check that the file resolution is aXb
using pure Javascript. How can I do that in the verifyFileUpload(event)
function?
-
event.target.files
return selected files data – Mohammad Commented Oct 3, 2018 at 12:15 - 2 Possible duplicate of stackoverflow./questions/8903854/… – clabe45 Commented Oct 3, 2018 at 12:25
- This questions has lot of answers online, even on stack overflow, please consider doing a quick search before posting a question. also Possible duplicate stackoverflow./questions/12570834/… – Wasim Sayyed Commented Oct 3, 2018 at 12:32
1 Answer
Reset to default 10Try the below way
window.URL = window.URL || window.webkitURL;
function verifyFileUpload(e)
{
var file = document.getElementById("input-id");
if (file && file.files.length > 0)
{
var img = new Image();
img.src = window.URL.createObjectURL( file.files[0] );
img.onload = function()
{
var width = this.naturalWidth,
height = this.naturalHeight;
console.log ("Image Width: " + width);
console.log ("Image Height: " +height);
};
}
}
<input type="file" id="input-id" accept="image/jpg" onchange="verifyFileUpload(event)">