Forum Home
Press F1
 
Thread ID: 84157 2007-10-26 03:50:00 HTML forms - filename without upload Erayd (23) Press F1
Post ID Timestamp Content User
605529 2007-10-26 03:50:00 I'm having a not-so-small HTML problem with an app I am writing. I am wanting to offer the user a 'browse' box that they can use to choose a file on their machine, and then send the full name & path of the file (but not the file itself) to the server.

I can do it with Javascript, but would like to avoid this if possible - it's a rather messy solution and doesn't degrade gracefully. Any ideas on how to do this in HTML?

Cheers,
Bletch

[Edit: Would also be great if they could have the option of choosing a folder rather than a file]
Erayd (23)
605530 2007-10-26 04:16:00 I just found this example - looks like it could be what you're wanting


<form action="www.cs.tut.fi
enctype="multipart/form-data" method="post">
<p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p>
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="datafile" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>

Just change the cs.tut.fi address (good for testing first tho) to your own and remove the text input paragraph if you dont want it
bevy121 (117)
605531 2007-10-26 04:33:00 I have tried the html code in my web site from bevy121 and it does display a form (in Frontpage 2000). I might test it on my server... kahawai chaser (3545)
605532 2007-10-26 06:14:00 I just found this example - looks like it could be what you're wanting

Just change the cs.tut.fi address (good for testing first tho) to your own and remove the text input paragraph if you dont want itThis form will upload the file - which is exactly what I don't want. What I'm trying to do is just capture the filename and path, not the file itself.
Erayd (23)
605533 2007-10-26 10:04:00 ok sorry - this is prolly not a very good way of doing it, but if you change the enctype from "multipart/form-data" to the default "application/x-www-form-urlencoded" it only sends the text - being the filename :)
as I say, prolly a terribly bad way of doing html, I know very little about it lol



<form action=" . cs . tut . fi/cgi-bin/run/~jkorpela/echo . cgi"" target="_blank">www . cs . tut . fi
enctype="application/x-www-form-urlencoded" method="post">
<p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p>
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="datafile" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>



The "sendback" script for the handler is here ( . cs . tut . fi/~jkorpela/forms/sendback . pl" target="_blank">www . cs . tut . fi) also if its of use to you
bevy121 (117)
605534 2007-10-26 11:40:00 I need the filename and the full path - not just the filename. The above approach sends only the filename. Erayd (23)
605535 2007-10-26 21:00:00 irc? mejobloggs (264)
605536 2007-10-26 22:09:00 Have you tried it?

It sends the full path
bevy121 (117)
605537 2007-10-26 22:25:00 XP pro sp2 - IE 6

even if user clicks a shortcut on their comp the full path will still be returned

return data string using the above code



Echoing submitted form data
textline (empty)
datafile C:\Documents and Settings\gdme\Desktop\test_file_for_path . txt

Processed 2007-10-26T22:53Z
bevy121 (117)
605538 2007-10-26 23:44:00 Have you tried it?

It sends the full pathI have tried it - it doesn't send the full path for all the major browsers (notably Opera), which is what I need. Working in just one or two browsers isn't good enough.
Erayd (23)
1 2