Jquery html5 file Upload image display image
I recently made a small example of how to display images when uploading user images. I found a lot of information on the Internet and could not do it. If so, I used jquery and html5 to implement it. Since the development was in linux, I was not able to test it in ie. In forefox, chrom is supported.
I. The code in html is:
Header phase:*
Ii. jquery js Code: path under different browsers
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 ; }
3. display images:
var strsrc=getObjectURL(this.files[0]);$("#show_img").attr("src",strsrc);