0
你好,我有下面的代码,从输入获取文件,图像,并将其张贴到PHP它都工作得很好,但我想先找到图像的高度和宽度。我该怎么做呢?这里是我的代码:Javascript获取图像的高度?
$(':file').change(function(){
file = this.files[0];
});
function doit(){
var formData = new FormData($('form')[0]);
//console.log(dataObj);
if(file.name.length < 1) {
TooBig = true
}
else if(file.size > 1000000) {
TooBig = true
}
else if(file.type != 'image/png' && file.type != 'image/jpg' && file.type != 'image/jpeg') {
TooBig = true
console.log("done");
}else{
TooBig = false
}
if(TooBig == false){
document.getElementById('submitbtn').innerHTML = 'Uploading';
$.ajax({
url: 'saveImage.php',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data){
console.log(data);
nextID = data;
cancel2();
}
});
}else{
document.getElementById('thumbage2').value = "";
document.getElementById('labelthumb2').innerHTML = ''+height;
}
}
我尝试使用
file.width;
,但它没有工作,有人可以帮我吗? 编辑:我想获得图像的高度,而它仍然在输入字段。
你可以得到这个工作在PHP中。 – Perumal
@ Perumal93即使如此,也没有必要。如果op想要使用JS,就这样吧 –
@DarylGill好的。 – Perumal