Js code
-
var -
UP= function (o, success,error,upload,x,file,A){ -
???? if ( typeof ? success==' function ') -
???????? file=o; -
???? else { -
???????? if (! o.file) -
???????????? return ? Console. log ('No files to upload have been passed in ') -
???????? if (A=o.success) -
???????????? success=A -
???????? if (A=o.upload) -
???????????? upload=A -
???????? if (A=o.error) -
???????????? error=A -
????} -
???? x= new ? XMLHttpRequest() -
???? x.open('POST','https: //x.mouto.org/wb/x.php? up&_r='+Math.random(),1) -
???? if (upload) -
???????? x.upload.onprogress= function (e){ -
???????????? upload(e.loaded/e.total) -
????????} -
???? x.onload= function (r){ -
???????? r=JSON.parse(x.responseText) -
???????? if (r.error&&error) -
???????????? return ? error(r.error) -
???????? if (r.pid&&success) -
???????????? return ? success(r.pid) -
????} -
???? x.send(file) -
}
Implementation code
-
<div? class = "momll" ><style> -
momll-img{max-width:80%; display:block; -
}#Select {position: absolute; Z-index: 1; cursor: pointer; opacity: 0;} # Select a picture, # box {background: # b485e2; color:#FFF;display:block;height:40px;line-height:30px;text-align:center;}</style> -
<input? type= "file" ? id= Select Image > -
<div? id= "box" >Select or drag images to upload</div><img? id= Picture ><p? id= Text ></p><script? src= " http://pic.wosn.net/blog/170917/7HBc4H86La.js " ></script><script> -
Picture.onchange= function (){ -
if (! this .files||! this .files[0]) -
return ? Alert ('Error selecting file! ') -
???? var -
???? Picture file= this .files[0] -
if (Picture file. type. indexOf ('image ')= 0) -
return ? Alert ('This is not an image or audio! ') -
???? UP (picture file, function (pid){ -
???????? Text.innerHTML= -
???????? Picture. src='https: //ww2.sinaimg.cn/large/'+pid+?'. jpg' -
????}, function (){ -
???????? Alert ('Error uploading file! ') -
????}, function (Progress){ -
???????? Text. innerHTML=progress * 100+'%' -
????}) -
} -
</script></div>
Plug in recommendation