Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the file path from HTML input form in Firefox 3

We have simple HTML form with <input type="file">, like shown below:

<form>   <label for="attachment">Attachment:</label>   <input type="file" name="attachment" id="attachment">   <input type="submit"> </form> 

In IE7 (and probably all famous browsers, including old Firefox 2), if we submit a file like '//server1/path/to/file/filename' it works properly and gives the full path to the file and the filename.

In Firefox 3, it returns only 'filename', because of their new 'security feature' to truncate the path, as explained in Firefox bug tracking system (https://bugzilla.mozilla.org/show_bug.cgi?id=143220)

I have no clue how to overcome this 'new feature' because it causes all upload forms in my webapp to stop working on Firefox 3.

Can anyone help to find a single solution to get the file path both on Firefox 3 and IE7?

like image 776
m_pGladiator Avatar asked Sep 17 '08 08:09

m_pGladiator


People also ask

How can I get full path of uploaded file in HTML using jquery?

var fullPath = $('#fileUpload1'). val();

How do you get input from a file in HTML?

The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute. Tip: Always add the <label> tag for best accessibility practices!

Where do HTML forms submit to?

An HTML form is used to collect user input. The user input is most often sent to a server for processing.


2 Answers

For preview in Firefox works this - attachment is object of attachment element in first example:

           if (attachment.files)              previewImage.src = attachment.files.item(0).getAsDataURL();            else              previewImage.src = attachment.value; 
like image 162
houba Avatar answered Sep 28 '22 01:09

houba


Actually, just before FF3 was out, I did some experiments, and FF2 sends only the filename, like did Opera 9.0. Only IE sends the full path. The behavior makes sense, because the server doesn't have to know where the user stores the file on his computer, it is irrelevant to the upload process. Unless you are writing an intranet application and get the file by direct network access!

What have changed (and that's the real point of the bug item you point to) is that FF3 no longer let access to the file path from JavaScript. And won't let type/paste a path there, which is more annoying for me: I have a shell extension which copies the path of a file from Windows Explorer to the clipboard and I used it a lot in such form. I solved the issue by using the DragDropUpload extension. But this becomes off-topic, I fear.

I wonder what your Web forms are doing to stop working with this new behavior.

[EDIT] After reading the page linked by Mike, I see indeed intranet uses of the path (identify a user for example) and local uses (show preview of an image, local management of files). User Jam-es seems to provide a workaround with nsIDOMFile (not tried yet).

like image 32
PhiLho Avatar answered Sep 27 '22 23:09

PhiLho