Link to home
Start Free TrialLog in
Avatar of DaisyWang
DaisyWang

asked on

How to upload local file?

Hi, there,

I need to implement following feature to my HTML:

*********************************************
text field 1           browser button 1
text field 2           browser button 2
.....

submit button
*********************************************

I need to click on each "browser button" and choose a local file name from a popup window, and put this file name into corresponding "text field".  When I click the "submit button", all local file in those text fields will be uploaded.

Can anybody tell me how to do that?

Daisy
ASKER CERTIFIED SOLUTION
Avatar of bruno
bruno
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
give BRUNO the points before i copy and paste what he's written!
lol...i lucked out and managed to be the first one here.  :-)
Avatar of DaisyWang
DaisyWang

ASKER

maybe you are same guy, haha :)
no im lexxwern
bruno is not lexxwern
also
lexxwern is not bruno

hope this helps, now DaisyWang you owe me points.

lhn
Daisy,

did what I posted help you at all?

Somewhat rude to come back and not comment on the problem at hand....


BRUNO
BRUNO its hurts even more when someelse is living in a more favourable timezone.
+0530 INDIA is really a bad one. i get no new quetions whether i log on in the evening or morning :-(

i guess you ppl have taken full adv. of reading the brief history of time, huh!?

Anyway,

lexxwern
lexxwern,

i have no idea what your comment has to do with the issue at hand.


BRUNO
bruno,

i'm trying your way these days, give me some time, if it works, i'll surely give you your points.

daisy
Daisy,

Thanks for coming back and commenting, let me know if you have any problems.  


BRUNO
Daisy:

The upload part will have to be done with some server side code as bruno suggests, but you could use javascript to populate text boxes with the two filenames you've browsed for if you wish.

If you're bored, give this a try and see what you think:

<html>
<head>
<script>
function populate_texts()
{
var selected1 = document.form1.file1.value
var selected2 = document.form1.file2.value

var seperated1 = selected1.split("\\");
var seperated2 = selected2.split("\\");

var no_of_sections1 = seperated1.length;
var no_of_sections2 = seperated2.length;

var last_portion1 = (no_of_sections1 -1);
var last_portion2 = (no_of_sections2 -1);

var filename1 = seperated1[last_portion1];
var filename2 = seperated2[last_portion2];

document.form1.text1.value = filename1
document.form1.text2.value = filename2
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="text1">&nbsp&nbsp<input type="file" name="file1">
<p>
<input type="text" name="text2">&nbsp&nbsp<input type="file" name="file2">
<p>
<input type="button" name="submitbutton" value="submit" onClick="populate_texts();">
</form>
</body>
</html>

All you'd need then is he active code to do the processing of the text boxes.

There's probably other ways, I was just killing time over a Lobster Thermidore luncheon :)

Neil
lexxwern,
Hello, I am Computer101, a Moderator on this site.  I have an issue with your comment.  What gives you the right to DEMAND that the questioner "give BRUNO the points before i copy and paste what he's written! ".  We are here to assit questioners, not demand things from them.  The questioner's history for accepting answers is not that great, but that give's you the right?  Also, what input to the questioners problem did you provide.  As I see it, nothing, so why did you post in this thread. I will monitor your actions and we will see how things go, but I ask that you tone things down.  If no related posts continue to be made, I will forward this to Admin for action.

Btw, I will not accept anymore comments in this questioner's thread concerning this but will open a question in Community Support concerning this matter.

Now DaisyWang, you do have open questions and I ask that you resolve those or I will have to go back to them and close them.

Thank you
Computer101
E-E Moderator
Explanation and Clarifications Posted here
https://www.experts-exchange.com/questions/Q.20279061.html


--------------------COPY--------------------
 okay.
i better get to say something.

first thnx big rat.

Daisy Said " maybe you are same guy, haha :)"
*Please note 'haha'* and my reply
     " no im lexxwern
       bruno is not lexxwern
       also
       lexxwern is not bruno

       hope this helps, now DaisyWang you owe me points.

       lhn"
was in the same tone

my comments there were not demanding anything, my comments weren't even serious, i guess bruno got that
by his saying "lol...i lucked out and managed to be the first one here.  :-)".

as you first language english havers say, i was kidding.

i also acknowledge that my comments there were not related to the topic and i will prevent "cluttering"
in the future.
but i would not want people incharge here to believe that i was in any way demanding anything from EE
User DaisyWang.

now i would ask Computer101 to delete this thread if it has solved its purpose, since it is not doing
me any favours.

lexxwern.
--------------------END----------------------
Sorry to get off topic and back to DaisyWang's question, but...

it's my understanding that any form submission that includes files requires that
    enctype="mulitpart/form-data"
be added to the form tag.

Regarding the javascript form field population from NTIVER, no need: <input type="file"> provides it's own field that displays the path to the selected file.

-corey
coreyit - I know, I was just stripping the path details so that the user could grab just the filename and extension.

I didn't know if it might be of use.

Neil :)
Daisy,
Any status.

Thank you
Computer101
E-E Moedrator
C101, I think you know what I'm gonna say here....

DaisyWang, you've been blacklisted for giving a C grade and not giving a comment why.


BRUNO
After review, grade changed.

Computer101
E-E Moderator
thanks.