Hello everybody,
I have a php page in which I used a image upload future. Here the users can upload the image by selecting the file name by using a browse button. Here my problem I want to display the image at the side the of the page before uploading the file into database. Can anyone help.
Regards,
Sarbas.
How to diaplay an image inside the page before uploading it.
Moderator: General Moderators
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
It's totally possible using javascript:
My example uses jQuery, but you could do it without. The general principle is to set the src of an img element to the value of the file input form control.
Code: Select all
$(function(){
$('#fileSelect').change(function(){
$('#previewPic').attr('src','file://'+$('#fileSelect').attr('value'));
});
});Code: Select all
<form method="post" action="">
<input id="fileSelect" type="file"/>
</form>
<img id="previewPic"/>- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
To use my code, you'll need to include jQuery: http://jquery.com
...or you can just do what I'm doing, but write it yourself without jQuery.
...or you can just do what I'm doing, but write it yourself without jQuery.