473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File Upload variation

MG
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.
Jul 29 '05 #1
8 1929
Gazing into my crystal ball I observed MG <po**@mpc1000.com> writing in
news:pa****************************@mpc1000.com:
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.


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
Jul 30 '05 #2
MG
>> 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.


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.

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.

Jul 30 '05 #3
Gazing into my crystal ball I observed MG <po**@mpc1000.com> writing in
news:pa****************************@mpc1000.com:
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.


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.

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.


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
Jul 30 '05 #4
MG wrote:
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.


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
Jul 30 '05 #5
MG
> Supplementary question: How is a clientside filename any business
of the server?


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.

Jul 30 '05 #6
MG wrote:
Supplementary question: How is a clientside filename any business
of the server?

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.

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
Jul 31 '05 #7
MG <po**@mpc1000.com> wrote:
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".


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

Aug 2 '05 #8
MG wrote:
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.


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

Aug 3 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pugi! | last post by:
Hi, I would like to upload office-document (doc, xls, ...) using a form to a website (apache, php, mysql) in a specific directory and if possible insert it into a table (MySQL-db). Is this...
2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
2
by: mark | last post by:
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage()...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
6
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.