Connecting Tech Pros Worldwide Help | Site Map

File Upload variation

MG
Guest
 
Posts: n/a
#1: Jul 30 '05
I'm in need of a form method similar to the typcial "file upload", but
rather than submitting the entire file, I need just the filename.

I cannot find anything as part of FORM that would allow this, short of
simply providing a text box, but I like the convenience of the file
selection dialogs.


Adrienne
Guest
 
Posts: n/a
#2: Jul 30 '05

re: File Upload variation


Gazing into my crystal ball I observed MG <post@mpc1000.com> writing in
news:pan.2005.07.29.23.22.50.988883@mpc1000.com:
[color=blue]
> I'm in need of a form method similar to the typcial "file upload", but
> rather than submitting the entire file, I need just the filename.
>
> I cannot find anything as part of FORM that would allow this, short of
> simply providing a text box, but I like the convenience of the file
> selection dialogs.
>
>
>[/color]

What ever you are using server side should be able to grab the file name,
and you can probably tell the script not to save the file to disk.

--
Adrienne Boswell
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
MG
Guest
 
Posts: n/a
#3: Jul 30 '05

re: File Upload variation


>> I'm in need of a form method similar to the typcial "file upload", but[color=blue][color=green]
>> rather than submitting the entire file, I need just the filename.
>>
>> I cannot find anything as part of FORM that would allow this, short of
>> simply providing a text box, but I like the convenience of the file
>> selection dialogs.
>>
>>[/color]
>
> What ever you are using server side should be able to grab the file name,
> and you can probably tell the script not to save the file to disk.[/color]


My apologies for not being as clear as I could. I'd rather not transfer
the file itself over the network.

However, I did find this:
http://www.cs.tut.fi/~jkorpela/forms/file.html

"A common problem with file input in forms is that form data gets sent but
only the name of the file is included. The reason is typically that the
form element does not contain the attributes mentioned above."

I think I am reading this to say that an incomplete form may not send the
file. There are several items "mentioned above". Time to get testing.

Adrienne
Guest
 
Posts: n/a
#4: Jul 30 '05

re: File Upload variation


Gazing into my crystal ball I observed MG <post@mpc1000.com> writing in
news:pan.2005.07.30.05.39.20.801251@mpc1000.com:
[color=blue][color=green][color=darkred]
>>> I'm in need of a form method similar to the typcial "file upload",
>>> but rather than submitting the entire file, I need just the filename.
>>>
>>> I cannot find anything as part of FORM that would allow this, short
>>> of simply providing a text box, but I like the convenience of the
>>> file selection dialogs.
>>>
>>>[/color]
>>
>> What ever you are using server side should be able to grab the file
>> name, and you can probably tell the script not to save the file to
>> disk.[/color]
>
>
> My apologies for not being as clear as I could. I'd rather not
> transfer the file itself over the network.
>
> However, I did find this:
> http://www.cs.tut.fi/~jkorpela/forms/file.html
>
> "A common problem with file input in forms is that form data gets sent
> but only the name of the file is included. The reason is typically that
> the form element does not contain the attributes mentioned above."
>
> I think I am reading this to say that an incomplete form may not send
> the file. There are several items "mentioned above". Time to get
> testing.
>
>[/color]

That's a good idea, but, to be sure, I would still check server side. What
if some browser misbehaves?

--
Adrienne Boswell
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Nick Kew
Guest
 
Posts: n/a
#5: Jul 30 '05

re: File Upload variation


MG wrote:[color=blue]
> I'm in need of a form method similar to the typcial "file upload", but
> rather than submitting the entire file, I need just the filename.
>
> I cannot find anything as part of FORM that would allow this, short of
> simply providing a text box, but I like the convenience of the file
> selection dialogs.[/color]

Short answer: you can't.

Longer answer: you could browse filesystems with a clientside application
iff the browser abandons its security. A signed applet could be an
option, though it's way OTT.

Untried answer: maybe you could play with a file-upload form, an
onsubmit() handler, and a serverside handler that can deal with
all eventualities.

Supplementary question: How is a clientside filename any business
of the server?

--
Nick Kew
MG
Guest
 
Posts: n/a
#6: Jul 30 '05

re: File Upload variation


> Supplementary question: How is a clientside filename any business[color=blue]
> of the server?[/color]

I'm working to migrate a desktop app to a web-based app. The app has
little need for a network in itself, but this is merely a self-initiated
academic exercise to exposed myself to another language.

The process would take several client filenames and send back a new file
with the filenames embedded in it to be used in non-computer hardware.
There is also another situation I am looking into where the files
themselves could be submitted, but I already know that is possible.


And thanks for the suggestions.

RobG
Guest
 
Posts: n/a
#7: Jul 31 '05

re: File Upload variation


MG wrote:[color=blue][color=green]
>>Supplementary question: How is a clientside filename any business
>>of the server?[/color]
>
>
> I'm working to migrate a desktop app to a web-based app. The app has
> little need for a network in itself, but this is merely a self-initiated
> academic exercise to exposed myself to another language.
>
> The process would take several client filenames and send back a new file
> with the filenames embedded in it to be used in non-computer hardware.
> There is also another situation I am looking into where the files
> themselves could be submitted, but I already know that is possible.
>
>
> And thanks for the suggestions.
>[/color]


Given the above environment, the following may suit though it is
dependent on JavaScript.

If no file is selected, form doesn't submit. If JavaScript is not
available, the form will submit only the hidden element with a value
of 'none'. The file input has no name and so will not be submitted
regardless of whether JavaScript is available or not.

Because the file input doesn't have a name, its position in the
elements collection is used to get its value.

<script type="text/javascript">
function getFilename( f ) {
var fn = f.elements[0].value;
if ( '' != fn ) {
f.elements['filename'].value = fn;
} else {
return false;
}
}
</script>

<form action="" onsubmit="return getFilename( this );">
<input type="file">
<input type="hidden" name="filename" value="none">
<input type="submit">
</form>

Note that this is unsuitable for the general web but may do the job on
an intranet where you can be more confident of JavaScript being available.

--
Rob
Jukka K. Korpela
Guest
 
Posts: n/a
#8: Aug 2 '05

re: File Upload variation


MG <post@mpc1000.com> wrote:
[color=blue]
> http://www.cs.tut.fi/~jkorpela/forms/file.html
>
> "A common problem with file input in forms is that form data gets sent
> but only the name of the file is included. The reason is typically that
> the form element does not contain the attributes mentioned above."
>
> I think I am reading this to say that an incomplete form may not send
> the file. There are several items "mentioned above".[/color]

The attributes I'm referring to are 'action', 'method', and 'enctype',
which are essential for making file submission work. But the most important
in this context is 'enctype'.

My statement discusses known behavior for _erroneous_ forms that contain a
file input field without having the attributes of the <form> element set
properly. So I would not count on building anything on the assumption that
something specific happens when you throw a malformed form at a browser.

At http://www.cs.tut.fi/~jkorpela/forms/file.html#name
I discuss the way browsers deal with the filename, which thet _may_ (and
mostly do, in practice) include into the form data headers. You would meet
the problem that most browsers include a pathname, which is generally
unusable outside the context of the user's system. Thus, you would need to
do some string manipulation to extract the assumed filename proper,
probably picking up the maximal trailing alphanumeric string, counting a
period as alphanumeric in this context.

There's no defined way to have such information included without having the
file content included as well. When some browsers behave that way, it's
nothing more than (questionable) error processing. In the WWW context,
which is implied in this group, it would hardly make any sense to deal with
pure filenames, even if you could in some sense get at them.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

SuicideAl
Guest
 
Posts: n/a
#9: Aug 3 '05

re: File Upload variation


MG wrote:[color=blue]
> I'm in need of a form method similar to the typcial "file upload", but
> rather than submitting the entire file, I need just the filename.
>
> I cannot find anything as part of FORM that would allow this, short of
> simply providing a text box, but I like the convenience of the file
> selection dialogs.[/color]

You could use a bit of a dirty hack like this [note: will only work on
IE not FF, is not very accessible and has no error checking.]. So I
wouldn't recommend using it in the public domain but it could be used
in a known environment, i.e. intranet :-)

<html>

<head>
<script language="javascript" type="text/javascript">

function click_filename() {

document.forms["file"].elements["filetoupload"].click();

}

function set_filename(f) {
document.forms["fname"].elements["filename"].value =
f.value.substr(f.value.lastIndexOf('\\')+1,f.value .length);
document.forms["file"].reset();
}

</script>
</head>

<body>

<form name="file" style="display:none;">

<input type="file" name="filetoupload" onchange="set_filename(this);"
/>

</form>

<form name="fname">

<input type="text" name="filename" />
<input type="button" name="filebutton" value="browse"
onclick="click_filename()" />

</form>

</body>

</html>

It does make me feel a bit unclean tho :-(

Al

Closed Thread