1

I need to obtain the String for the file that is being uploaded from forms to store in the database.

I am using the usual form input file element

 input type="file" name="some_name"

I found a couple JS scripts that allow me to do useless things like display the string in a dialog box, etc.

I need this as an element on the request object or as a hidden field on my page when the form is posted.

TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208

2 Answers2

2

You should be able to do something like this:

<form method="POST">
    <input type="file" name="some_name"
     onchange="document.getElementById('hidden_file').value = this.value;" />

    <input type="hidden" id="hidden_file" value="" />
    <input type="submit" />
</form>

I believe that will work in all browsers if you simply want to store the filename, and not the full path.

Community
  • 1
  • 1
Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
1

You won't get a very useful value. Some browsers will only give you the final name part of the file path, while IE will give you a path with a bogus directory name.

I think that the "safe" fragment of the file name should already be passed in to you as part of the part header in the multipart post body.

Pointy
  • 405,095
  • 59
  • 585
  • 614