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