Hello:
I'm sorry but you can't do that, why? security reasons, read below:
Input Type=File
http://www.blooberry.com/indexdot/html/tagpages/i/inputfile.htm
"Internet Explorer, Netscape and Opera do not use the VALUE attribute
as the default contents of the input area. Any default value set via
HTML is not usable via scripting and the DOM as well (hence it is not
listed as 'supported' in any of the browsers.) If a user enters text
in the field however, that value is then reachable via the DOM as it
normally would be for a normal INPUT field (via the .value property.)
The reason for this behavior would presumably be to ensure the
security/safety of users against malicious authors."
And here you can read a very interesting discussion about this:
File input (or "upload") in HTML forms - Setting the default filename
http://www.cs.tut.fi/~jkorpela/forms/file.html#value
"The HTML 4.0 specification says that for a file input field, browsers
(user agents) "may use the value of the value attribute as the initial
file name". This however is usually not supported by browsers. The
usual explanation is "security reasons". And indeed it would be a
security risk if files from the user's disk were submitted without the
user's content. It might be all too easy to lure some users into
submitting some password files! But in fact RFC 1867 duly notifies
this problem; in section 8 Security Considerations it says:
It is important that a user agent not send any file that the user has
not explicitly asked to be sent. Thus, HTML interpreting agents are
expected to confirm any default file names that might be suggested
with <INPUT TYPE=file VALUE="yyyy">."
I recommend you to read the entire page, it's very interesting and it
points you to a link where a user did that on Netscape:
File input (or "upload") in HTML forms - The appearance of the Browse
button and the filename box
http://www.cs.tut.fi/~jkorpela/forms/file.html#present
How to assign a value to "Browse..." button?
http://groups.google.com/groups?oi=djq&as_umsgid=%3C38119FEE.DFF60EBA%40sector27.de%3E
I include some code to show you how you can read that field but now
write to it even using JavaScript:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n);
return x;
}
function MM_showProp(objName,x,theProp,theValue) { //v3.0
var obj = MM_findObj(objName);
if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("
alert(obj."+theProp+");");
}
function MM_setTextOfTextfield(objName,x,newText) { //v3.0
var obj = MM_findObj(objName); if (obj) obj.value = newText;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" enctype="multipart/form-data" method="post"
action="">
<input type="file" name="file">
<input type="button" name="Button" value="Show"
onClick="MM_showProp('file','','value');">
<input type="button" name="Button" value="Set"
onClick="MM_setTextOfTextfield('file','','yourtext');">
</form>
</body>
</html>
I hope this is what you were looking for and don't hesitate to ask for
any clarification.
Regards. |
Request for Answer Clarification by
yochad-ga
on
03 Sep 2002 15:45 PDT
maybe i should describe what it is that i am doing to help you help
me.
I wrote a cgi script that (when called with no parameters) shows a
menu. The menu has your standard radio buttons, and checkboxes and it
also has the <input type=file...> tag. When the user fills in all of
the necessary feilds and clicks on the submit button, the script does
a query on a data base and combines that information wiwth
prespecified information stored on the users computer in the file that
they selected and shows all of that info in an intelligable format to
the user (we'll call that the info page).
However the specifications have been modified now so that the menu
will again appear at the top of the information page so that the user
can change the selections that were made. When the info page comes up,
all of the selections on the menu are defaulted to the most recent
selections that the user has made, so that if the user only wants to
change 1 of the many feilds and resubmit the query, it can be done
without having to worry about setting up the menu all over again.
However, because there isn't a way to default this -> <input
type=file> , i need a way to be able to store the last filename that
the user entered and then re-upload that file if the user decides not
to change that field in the menu. How do i do that?
|
Clarification of Answer by
joseleon-ga
on
03 Sep 2002 23:37 PDT
Hello:
>Then in my perl cgi script query the value of the txtbox parameter
>and use that value (which would be a file name on the user's
computer) as
>the name of the file to upload.
A file is uploaded by the browser to your server when you specify the
enctype="multipart/form-data" in your form, is the browser who uploads
the file, not you, so what you say it's not possible, check here:
The enctype attribute
http://www.cs.tut.fi/~jkorpela/forms/file.html#enctype
"It seems that the HTML 4.0 specification contains no explicit
requirement that enctype="multipart/form-data" be used if the form
contains a file input field (although it explicitly recommends that).
But e.g. IE 4 and Netscape 4 handle form submissions incorrectly if
the enctype is defaulted in such a case: they send the name of the
file instead of its content!"
>i need a way to be able to store the last filename that
>the user entered and then re-upload that file if the user decides not
>to change that field in the menu. How do i do that?
If the user leaves the input file in blank, it means he/she doesn't
want to make any change, you can place a label "Leave in blank to
don't make changes" just at the side of the input file. I know it's
not very polite, but be aware this is a browser limitation and you
have to find a workaround bearing in mind you cannot upload a file to
the server if the user has not selected it.
Regards.
|