469,343 Members | 5,623 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

Writing a file upload function

46
hi!

i have a table..which consists of a upload and browse buttons and some place to display an image.if i browse a file(jpg,gif) and upload,it should appear in place of image in that table itself.my code is

[code=html]<form method="POST" ENCTYPE="multipart/form-data" ACTION="abc.Action">
<table cellpadding=0 cellspacing=0 border=0 style='top:40px;left:0px;position:absolute;z-index:0;' width=130px >

<TR>
<TD vAlign=top width=8 bgColor=white><IMG src="../../images/a.gif"></TD>
<TD background="../../images/b.gif" ></TD>
<TD vAlign=top align=right width=20 bgColor=white><IMG src="../../images/patreg/c.gif"></TD>
</TR>
<TR >
<TD background="../../images/d.gif" nowrap></TD>
<TD bgcolor=#dbeaf5>

<table height=250px><tr><td valign=top>
<img src="../../g.gif" style="height:100px;width:100px;" > </td></tr>

<tr><td valign=bottom><input type="file" name="file" id="uploadme" size=1 />
<input type="button" value="UpLoad" onclick='javascript:UploadFile();'class=ButtonStyl es align=bottom></td></tr>
</table>
</td>
<TD background="../../images/e.gif" ></TD>
</tr><tr>
<TD vAlign=bottom width=8 bgColor=white><IMG src="../../images/f.gif"></TD>
<TD background="../../images/g.gif" ></TD>
vAlign=bottom align=right width=20 bgColor=white><IMG src="../../images/h.gif"></TD>
</TR>
</TBODY>
</table>
Expand|Select|Wrap|Line Numbers
  1. <form method="POST" ENCTYPE="multipart/form-data" ACTION="abc.Action">
wht should i write in the uploadFile() function???
Aug 29 '07 #1
13 6640
dmjpro
2,476 2GB
Hi Honey!
You should use Proper Code tags.
Anyway you need not to have your own function.
There is FILE tag in HTML.
Look for help in Google on File HTML Tag.
Best of luck.

Kind regards,
Dmjpro.
Aug 29 '07 #2
pbmods
5,821 Expert 4TB
Heya, Honey99.

Changed thread title to better describe the problem.

Simply submit the form to upload the file.
Aug 29 '07 #3
honey99
46
Heya, Honey99.

Changed thread title to better describe the problem.

Simply submit the form to upload the file.

no...actually what i want is when i upload an image file it should be displayed in that table itself..can anybody give me an example for uploading an image
Aug 29 '07 #4
acoder
16,027 Expert Mod 8TB
no...actually what i want is when i upload an image file it should be displayed in that table itself..can anybody give me an example for uploading an image
To upload an image, you will need the HTML input type=file element on the client-side, the form must be posted with the enctype changed to "multipart/form-data" and a server-side script which moves it to the upload location.

If you want to display in that table, submit the form to the same page and let the server-side script deal with changing the image. Now if you want to do this without reloading the page, you will need to use an iframe.
Aug 29 '07 #5
pbmods
5,821 Expert 4TB
Heya, Honey99.

You can set the src of an image to the local path of the image file (by getting the value of the file input), but for security reasons, many browsers specifically prevent this.

I think at this point, only IE allows you to do that out-of-the-box.

Note that for security reasons, the User has to submit the form to upload the file. This ensures that a malicious script cannot upload files without the User's consent.

Once the User has submitted the form, you can redirect back to the form and output an image tag that displays the newly-uploaded image.
Aug 29 '07 #6
honey99
46
thank u for u r guidelines....i need an example to upload an image in the same page....can anybody post me an example codefor this...
Aug 29 '07 #7
acoder
16,027 Expert Mod 8TB
thank u for u r guidelines....i need an example to upload an image in the same page....can anybody post me an example codefor this...
Without refreshing/reloading the page or just to the same page?
Aug 29 '07 #8
honey99
46
i'll be thankful to you if u send me the example code without refreshing the page...
Aug 29 '07 #9
acoder
16,027 Expert Mod 8TB
i'll be thankful to you if u send me the example code without refreshing the page...
Why reinvent the wheel? Try this link or search for "ajax file upload".
Aug 29 '07 #10
honey99
46
Why reinvent the wheel? Try this link or search for "ajax file upload".
the link you gave has PHP source code....but i want JSP code to upload image in same page wothout refreshing the page
Aug 30 '07 #11
acoder
16,027 Expert Mod 8TB
the link you gave has PHP source code....but i want JSP code to upload image in same page wothout refreshing the page
If you want JSP, ask in the Java forum. It doesn't matter what the sever-side language is. The example allows you to upload the image without unloading the page. Just convert the PHP to JSP.
Aug 30 '07 #12
pbmods
5,821 Expert 4TB
Heya, Honey99.

The idea behind doing an "AJAX" file upload is that, since you HAVE to submit a form to upload files, you put the form in an iframe and disguise it to look like it's part of the page.

Then, when the User submits the form, you load another page in the iframe that calls some JavaScript that updates the src of the preview image to the URL of the file he just uploaded.
Aug 30 '07 #13
pbmods
5,821 Expert 4TB
Have a look at this article.
Oct 30 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.