File Control Set Value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

File Control Set Value

Post by icesolid »

I was wondering if there is anyway to set the value of a file control box prior to submit. Here is my code for the control:

Code: Select all

<tr>
    <td><b>Picture:</b></td>
    <td><input type="file" size="25" name="userfile" value="File Name Here" class="form"></td>
  </tr>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there is none.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

feyd wrote:there is none.
otherwise it would be a security breach. Consider this:

Code: Select all

<form action="gather_private_info.php" method="POST" onload="this.submit();">
  <input type="file" name="theFile" value="c:\private\info.txt">
</form>
This form would send itself on its load without any user interaction, effectively stealing user's c:\private\info.txt file. That's why no decent browser would allow you to preset file inputs' values.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Thank You

Post by icesolid »

Well, thank you for the more detailed reply Weirdan. Feyd's reply was not exactly "informational".

But now that I know it is not possible to set the value, I still need help coming up with a solution.

I have an admin program when the user adds information to a MySQL database along with uploading a picture to the server. I also allow the user to edit this information and update the picture attached to the information.

But if the user does not choose to update the picture it submits a blank value to the program, which I have programmed to display an error. Any suggestions?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

I don't quite understand your requirements. Is it required to update a picture whenever information has changed? Or is it ok to update the information and leave the old picture?
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

How It Works

Post by icesolid »

It is ok to update the information and leave the old picture.
Post Reply