头像上传HTML代码:
<form action="/index.php?m=&c=User&a=uploadImage" method="post" id="formid" enctype= "multipart/form-data" style="display: block;"> <input id="upfiles" class="upfiles" type="file" name="log" onchange="uploadOperate();"> <a class="pic-img"> <img class="showimg" width="100px" onclick="" src=""> </a> <input type="submit" value="提交" class="btn2"> </form>
上传之后显示当前头像:
$("#upfiles").change(function(){ var objUrl = getObjectURL(this.files[0]) ; if (objUrl) { $(".showimg").attr("src", objUrl); } }) function getObjectURL(file) { var url = null; if (window.createObjectURL != undefined) { // basic url = window.createObjectURL(file); } else if (window.URL != undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file); } else if (window.webkitURL != undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file); } return url; }
时间: 2024-10-12 05:46:22