[英]ajax file upload image get height and width
我希望能够更改使用Ajax上传的图像的高度。
这是我的代码:
$(function(){
$("#submitimage").click(function(){
var data = new FormData(),
// ClientHeight is not getting the image height it is getting the height of some other element.
height = $("#file")[0].clientHeight,
width = $("#file")[0].clientWidth,
FileName = $("#file").val();
console.log(height);
console.log(width);
FileName = FileName.replace("C:\\fakepath\\", "");
data.append('file', $('#file')[0].files[0]);
$.ajax({
type: "POST",
url: "upload_file.php",
cache: false,
contentType: false,
processData: false,
data: data,
success: function(data) {
newimage = "<br><img src='uploadedimages/"+FileName+"' width='"+width+"' height='"+height+"' alt='new image' /><br>";
$(newimage).appendTo(".current-bulletin");
}
});
});
});
我使用console.log获取返回的高度和宽度,并且始终为22x272,因此我相信clientheight正在获取文件按钮的高度或类似的高度。
我可以从那里获得高度吗?还是最好以某种方式获得图像的高度,然后再加载它,然后进行更改?
因此,使用javascript我仍然没有找到执行此操作的方法,但是我为图像提供了一个new-img类,并在CSS中使它具有最大宽度:100%; 尽我所能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.