tags:

views:

170

answers:

1

Ok I really didn't know how else to sum it up for the title. I need to create a form where a user can specify an existing file, but I don't need to upload it (it's on a shared server already accessible) -- I just need to grab the filename and save it in the database so it's linked to other data.

I thought about the input tag as it provides a convenient already done interface to the user's filesystem, but I don't know if it's possible to use it without the acutal upload (leaving out enctype="multipart/form-data" doesn't seem to work). Can I tweak this to make it work, or is there any way to do it other than writing a custom mini file browser?

EDIT: I need the full path name of the file, asking the users to enter it is out of the question...

+2  A: 

You could place the <input type="file"> outside your HTML form, and then use the onChange event to fill an <input type="hidden"> within the form that gets posted:

<input type="file" 
       onchange="document.getElementById('hidden_file').value = this.value;" />

<form method="POST">
    <input type="hidden" id="hidden_file" value="" />
    <input type="submit" />
</form>
Daniel Vassallo
This is brilliant, but is there really no way of retrieving the full path too?
kemp
Unfortunately: http://stackoverflow.com/questions/1676035/cant-get-the-complete-address-while-uploading-a-file, but you may want to investigate further: http://stackoverflow.com/questions/81180/how-to-get-the-file-path-from-html-input-form-in-firefox-3
Daniel Vassallo
Too bad, thanks anyway for your answer
kemp