473,385 Members | 1,535 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,385 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 6824
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.