[英]Uncaught type error for input type file
I have a form and I am trying to upload the file but i have to get the file to upload it but I am unable to do so as I am getting this error 我有一个表格,我正在尝试上传文件,但是我必须获取文件才能上传,但是由于出现此错误,我无法这样做
main.js:5 Uncaught TypeError: Cannot read property 'value' of null main.js:5未捕获的TypeError:无法读取null的属性“值”
function upload() {
var data = new XMLHttpRequest();
var url = "includes/upload.php";
var file = document.getElementById("filename").value;
var image = document.getElementById("image").value;
var span = document.querySelector('#uploadPreview[style]'),
a = window.getComputedStyle(span, null).transform,
b = window.getComputedStyle(span, null).transformOrigin;
val = 'transform:' + a + ';transform-origin:' + b + ';backface-visibility: hidden;';
var vars = "style=" + val + "&image=" + image + "&filename=" + file;
data.open("POST", url, true);
data.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
data.onreadystatechange = function() {
if (data.readyState == 4 && data.status == 200) {
var return_data = data.responseText;
document.getElementById("comment_box").innerHTML = return_data;
}
}
data.send(vars);
}
My HTML code: 我的HTML代码:
<form method="POST" enctype="multipart/form-data" style="text-align:center;">
<input id="uploadImage" type="file" id="image" name="image" style="margin:auto;" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="hidden" id="filename" name="filename" value="<?php if(!empty($data['profile_pic'])) { echo $data['profile_pic'];} ?>" />
<button type="button" name="update_picture" class="btn_form" onclick="upload();">Update Picture</button>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.