<input type=file> - return file name without path?

J

jonesy

Is it possible using <input type="file"> to return the file name
without the path?

If not, is there any other way of coding a "browse" button that after
selecting a file it returns just the file name into the text box?

Thanks.
 
J

Jukka K. Korpela

Scripsit jonesy <3:
Is it possible using <input type="file"> to return the file name
without the path?

Maybe. You can't count on that, though. Browsers are expected to do so, but
most don't.
If not, is there any other way of coding a "browse" button that after
selecting a file it returns just the file name into the text box?

No.

What's your _real_ problem? Please don't forget to illustrate it with a URL
if you want to have it solved.
 
N

nice.guy.nige

While the city slept, jonesy <3 (3" <[email protected]) feverishly
typed...
Is it possible using <input type="file"> to return the file name
without the path?

Well.... technically, it is only the filename that is "returned" to the
processing script...
If not, is there any other way of coding a "browse" button that after
selecting a file it returns just the file name into the text box?

You could possibly use some client-side javascript to get the filename and
leave the path behind, use a hidden field to hold the actual full path of
the file to be uploaded, and populate a textbox with just the filename, but
it is a bit convoluted. What is your reasoning for this?

You're quite welcome old bean ;)

Cheers,
Nige
 
D

Dan

jonesy said:
Is it possible using <input type="file"> to return the file name
without the path?

If not, is there any other way of coding a "browse" button that after
selecting a file it returns just the file name into the text box?

You should program your back-end server script, which receives the
results of such a form, to process the field as needed (including
stripping out the path), rather than relying on the browser to send
exactly what you want.

Note that the syntax of a path may vary greatly between different
operating systems.
 
J

jonesy

Hi All,

Thanks for your advice.

The purpose for retrieving the filename from a form:

I have a database that stores the file name. This filename is taken by
a java servlet which displays a link to the file on the website.

I wanted the form to load the file to unix box, while sending the
filename to java servlet.

Not sure if this makes sense?

I don't have much experience in coding - I'm a first year student at my
first I.T. industry experience.
 
J

Jukka K. Korpela

Scripsit jonesy <3:

Who's All and why should we know him? Please start with a quote or
paraphrase in the future, to give context.
The purpose for retrieving the filename from a form:

You could have saved everyone's time, especially yours, by starting with a
description of the original problem rather than assumed solution, which is -
surprisingly - not a completely dead end, though tricky, slippery, and
unnecessary complex. Any recognition of the "file name" from the form data
is heuristic at best, and usually pointless.
I have a database that stores the file name.

Which "the" file name? The file name of the input file, if any (there's no
law against browsers supporting file input that is not taken from a file at
all), should almost always be immaterial to the processing of the form data.
Sometimes you could consider using it as a name for something that you store
on the server, but what would do, for example, with a file name containing
only Chinese characters?

So it's much better to prompt the user for some suitable name to be used for
the file on the server, or for the data to be entered in a database.
This filename is taken
by a java servlet which displays a link to the file on the website.

This would result in interesting situations if the filename contains
non-ASCII characters, wouldn't it? It could contain them even if it were
direct user input, but then you would probably more easily remember to
_check_ the input for acceptability and to prompt for a new name if needed.

So just add a text input field for the file name (or data set name, or
whatever you call it), or generate a name with some algorithm if it need not
be mnemonic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top