PDA

View Full Version : HTML forms - filename without upload



Erayd
26-10-2007, 03:50 PM
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]

bevy121
26-10-2007, 04:16 PM
I just found this example - looks like it could be what you're wanting


<form action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi"
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

kahawai chaser
26-10-2007, 04:33 PM
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...

Erayd
26-10-2007, 06:14 PM
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.

bevy121
26-10-2007, 10:04 PM
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="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi"
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 (http://www.cs.tut.fi/~jkorpela/forms/sendback.pl) also if its of use to you

Erayd
26-10-2007, 11:40 PM
I need the filename and the full path - not just the filename. The above approach sends only the filename.

mejobloggs
27-10-2007, 09:00 AM
irc?

bevy121
27-10-2007, 10:09 AM
Have you tried it?

It sends the full path

bevy121
27-10-2007, 10:25 AM
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

Erayd
27-10-2007, 11:44 AM
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
29-10-2007, 09:28 PM
bump.