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

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

We have simple HTML form with , like shown below:

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

    This is an example that could work for you if what you need is not exactly the path, but a reference to the file working offline.

    http://www.ab-d.fr/date/2008-07-12/

    It is in french, but the code is javascript :)

    This are the references the article points to: http://developer.mozilla.org/en/nsIDOMFile http://developer.mozilla.org/en/nsIDOMFileList

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

    We can't get complete file path in FF3. The below might be useful for File component customization.

    <script>
    
    function setFileName()
    {
        var file1=document.forms[0].firstAttachmentFileName.value; 
    
        initFileUploads('firstFile1','fileinputs1',file1);
        }
    function initFileUploads(fileName,fileinputs,fileValue) {
        var fakeFileUpload = document.createElement('div');
        fakeFileUpload.className = 'fakefile';
        var filename = document.createElement('input');
        filename.type='text';
        filename.value=fileValue;
        filename.id=fileName;
        filename.title='Title';
        fakeFileUpload.appendChild(filename);
        var image = document.createElement('input');
        image.type='button';
        image.value='Browse File';
        image.size=5100;
        image.style.border=0;
        fakeFileUpload.appendChild(image);
        var x = document.getElementsByTagName('input');
        for (var i=0; i&lt;x.length;i++) {
            if (x[i].type != 'file') continue;
            if (x[i].parentNode.className != fileinputs) continue;
            x[i].className = 'file hidden';
            var clone = fakeFileUpload.cloneNode(true);
            x[i].parentNode.appendChild(clone);
            x[i].relatedElement = clone.getElementsByTagName('input')[0];
            x[i].onchange= function () {
                this.relatedElement.value = this.value;
            }}
        if(document.forms[0].firstFile != null && document.getElementById('firstFile1') != null)
        {
        document.getElementById('firstFile1').value= document.forms[0].firstFile.value;
        document.forms[0].firstAttachmentFileName.title=document.forms[0].firstFile.value;
        }
    }
    
    function submitFile()
    {
    alert( document.forms[0].firstAttachmentFileName.value);
    }
    </script>
    <style>div.fileinputs1 {position: relative;}div.fileinputs2 {position: relative;}
    div.fakefile {position: absolute;top: 0px;left: 0px;z-index: 1;}
    input.file {position: relative;text-align: right;-moz-opacity:0 ;filter:alpha(opacity: 0);
        opacity: 0;z-index: 2;}</style>
    
    <html>
    <body onLoad ="setFileName();">
    <form>
    <div class="fileinputs1">
    <INPUT TYPE=file NAME="firstAttachmentFileName" styleClass="file" />
    </div>
    <INPUT type="button" value="submit" onclick="submitFile();" />
    </form>
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题