displaying image after Choose File, before upload

醉酒当歌 提交于 2019-12-12 02:25:57

问题


how can after choose image and before upload (before insert in database) displaying image?

this code not displaying image:

var a = $('<img src="' + g.STRING.selected.replace('$file', v) + '" alt="Angry face" width="50" height="50" />'),


<input type="file" name="image' >

With respect


回答1:


You can use the HTML5 File API (tutorial) to display the selected file. The best way is probably to use a FileReader to get a dataURL of the file and assign it to a src of an img.




回答2:


I think you can check this tutorial (look at the "New hotness" section) for a jQuery solution




回答3:


There are Many JavaScript functions written out there to render an image on the page using response.write and these methods all you have to do is search the Google.

but why you want to do a client side display ? even yahoo or many famous site do not handle rendering image in this way... they upload an image in a temporary database and if the user confirms it will be copied in the permanent database.

without server side verification you need many lines of java script code that may behave differently in different browsers.

hope i helped you a bit



来源:https://stackoverflow.com/questions/6799246/displaying-image-after-choose-file-before-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!