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

前端 未结 8 1770
臣服心动
臣服心动 2020-11-22 02:12

We have simple HTML form with , like shown below:

相关标签:
8条回答
  • 2020-11-22 02:19

    One extremely ugly way to resolve this is have the user manually type the directory into a text box, and add this back to the front of the file value in the JavaScript.

    Messy... but it depends on the level of user you are working with, and gets around the security issue.

    <form>
        <input type="text" id="file_path" value="C:/" />
        <input type="file" id="file_name" />
        <input type="button" onclick="ajax_restore();" value="Restore Database" />
    </form>
    

    JavaScript

    var str = document.getElementById('file_path').value;
    var str = str + document.getElementById('file_name').value;
    
    0 讨论(0)
  • 2020-11-22 02:23

    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;
    
    0 讨论(0)
  • 2020-11-22 02:26

    Simply you cannot do it with FF3.

    The other option could be using applet or other controls to select and upload files.

    0 讨论(0)
  • 2020-11-22 02:28

    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).

    0 讨论(0)
  • 2020-11-22 02:28

    This is an alternate solution/fix... In FF3, You can retrieve file's full path in a textbox instead of file browse box. And that too... By drag/dropping the file!

    You can drag drop your file into a text box in your html page. and it will display the file's complete path. This data can transferred to your server easily or manipulate them.

    All you have to do is to use the extension DragDropUpload

    http://www.teslacore.it/wiki/index.php?title=DragDropUpload

    This extension will helps you in drag dropping files into your File Browse (Input file) box. But still you wont able to get the file full path, If you try to retrieve.

    So, I tweaked this extension a little. In the way I can drag drop a file on to any "Text Input" box and get the file full path. And thus I can able to get the file full path in FF3 Firefox 3.

    0 讨论(0)
  • 2020-11-22 02:29

    Have a look at XPCOM, there might be something that you can use if Firefox 3 is used by a client.

    0 讨论(0)
提交回复
热议问题