Page 1 of 1
How to diaplay an image inside the page before uploading it.
Posted: Thu Feb 08, 2007 9:19 am
by sarbas
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.
Posted: Thu Feb 08, 2007 9:49 am
by feyd
At minimum, if possible, that would not involve PHP but Javascript.
Posted: Thu Feb 08, 2007 9:53 am
by Kieran Huggins
It's totally possible using javascript:
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"/>
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.
Posted: Fri Feb 09, 2007 4:48 am
by sarbas
hi Kieran Huggins,
thansk for your relply. i've used your code. but it's not working.can you give correct syntax for that script.
Hopefully waiting for your reply.
Sarbas
Posted: Fri Feb 09, 2007 5:00 am
by Kieran Huggins
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.