473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 6827
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

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

Similar topics

4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
6
by: darrel | last post by:
I'm struggling with an odd permissions problem I have with one of my functions. It takes a file, writes a directory, and then uploads some files to it. This works. Once. Any subsequent attempt and...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
4
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.