Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms & files

Status
Not open for further replies.

dkdude

Programmer
Jun 16, 2003
849
DK
Is it possible to (pre)set the filename in a form/input box? I can read the value but can't seem to set it. Maybe securrity issue?

Any thoughts?
 
Show what code you have so we can get a better idea what you're trying to do. In a text input, you use:
Code:
value="some value"


Lee
 
Hi Lee,

Yes, the value property works -for reading the filename. I would like to be able to set it to a default value/filename if possible at all ...

The code looks something like this:
Code:
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
  <title>Preset filename form</title>
</head>
<body onload="document.f1.userfile.value='C:\Documents and Settings\Me\Desktop\Plan.cdr'">
  <form enctype="multipart/form-data" action="doit.php" method="POST" name="f1">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send now" />
  </form>
</body>
</html>

Thanks
 
You cannot write the name for type="file".
All aspects of the object are read only.

At my age I still learn something new every day, but I forget two others.
 
Thanks,

So. Here's my problem. I wanted to make a drag'n'drop file upload this way:

Have a shortcut to my browser on my desktop - with a predefined opening URL. That works.

Dragging a file and dropping it on the shortcut and opens the desired page. I made a serverside script that pulls the filename (query string) from the URL posted.

All works so far. Except for inserting the client drive:/path/filename into the form.

I was hoping for a way to put that filename into a form element to be able to upload it.

Any ideas? Maybe it just can't be done?
 
type="file" returns an object reference to the selected file and passes this to your server side script when the form is submitted. Without this object reference you are NOT able to reach the file in order to upload it.
The object reference is much more than just the path/filename. The only way to establish the object reference is by using the browse button supplied by use of the type="file" form field. Just returning a path to the file will never give you permissions to access that file on the client's PC.

Normally you cannot access files on the client's machine for security reasons. The type="file" with it's inherant browse button allows the client to take actions that act as a way to ensure that the file reference is the direct result of client actions and not just code that could be malicious.

You could write your own activex component to do the drag and drop upload in which case you would need the client to either approve the activex command each time it is executed, or have the activex component registered so that it operates with local trust, or have a client-side piece of software to handle the uploads.

Using ActiveX would of course limit you to IE browsers.


At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top