[whatwg] What should the value attribute be for multi-file upload controls in WF2?

Michael A. Puls II shadow2531 at gmail.com
Sat Jun 21 08:48:24 PDT 2008


On 6/21/08, Matthew Paul Thomas <mpt at myrealbox.com> wrote:
> On Jun 20, 2008, at 2:44 PM, Lachlan Hunt wrote:
>
> > ...
> > In each one, I selected a file named test.txt from within my home or My
> Documents directory.  These are the vaules returned in each browser:
> >
> > Windows browsers:
> > IE 8:         test.txt
> > IE 7 mode:    test.txt
> > Firefox 2:    D:\My Documents\test.txt
> > Firefox 3:    test.txt
> > Opera 9.5:    C:\fake_path\test.txt
> > Safari 3.1.1: D:\My Documents\test.txt
> >
> > Mac browsers:
> > Firefox 3:    test.txt
> > Opera 9.5:    C:\fake_path\test.txt
> > Safari 4 (Developer Preview): /Users/lachlanhunt/test.txt
> > ...
> > Since Both Firefox 3 and IE 8 only return the file name, and Opera 9.5
> refuses to return the real path anyway, maybe we should define that when
> there's only a single file selected, it returns just the file name.
> > ...
> > --
> > Lachlan Hunt - Opera Software
> >
>
>  If this needs to be standardized for interoperability (though it's not
> clear to me that it does), it might help to know why Opera goes to the
> trouble of providing a fake path, rather than providing just the filename as
> Internet Explorer 7 and Firefox 3 do. Was this needed for Web site
> compatibility?

FF2, Safari and IE7 (as opposed to IE7 mode in IE8) show the full
path. Some sites that were only tested for windows browsers probably
expected a full path and tried to get the substr after the last \.
However, they probably checked to see if a \ existed first and if it
didn't, they didn't do anything. My guess at least.

But, now that FF3 and IE8 return just a filename, maybe those sites
are starting to fix things to just assume a filename. Not sure.

Anyway, the use case for .value is:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <p>File to attach: <p>
        <p><input type="file"
onchange="document.getElementsByTagName('p')[0].innerHTML +=
this.value;"></p>
        <button>Upload</button>
    </body>
</html>

And, the use case for .files is:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <script>
            function showFileNames(files) {
                var pre = document.getElementsByTagName("pre")[0];
                var s = "";
                for (var i = 0; i < files.length; ++i) {
                    if (i > 0) {
                        s += "\n";
                    }
                    s += files[i];
                }
                pre.innerHTML = s;
            }
        </script>
    </head>
    <body>
        <p>Files to attach:<p>
        <pre></pre>
        <p><input type="file" max="4" onchange="showFileNames(this.files)"></p>
        <button>Upload</button>
    </body>
</html>

(.value could be used instead of .files, but it'd have to return a
platform-specific separated list that you would have to parse into an
array first in this situation)

-- 
Michael



More information about the whatwg mailing list