Why doesn't IE9 accept files with filenames over 230?

What am I trying to do?

I am trying to validate a file after selecting it with an input type = "file" tag. One test is to make sure the filename is less than 200 characters long.

What have I done so far?

http://jsfiddle.net/joanferns00/ajeec780/4/ When I try to download the following sample file (a file with the file name 230) 234_aaaaa6JHmFop6Va6JHmFRsdK7fxn1HtVkpl5UREy7cn4yC4hlHuW87qDp2fEg3YQlZCETrkBbLqIgtAqlklyahRIH0hCzSUO234_op6Va6JHmFRsdK7fxn1HtVkpl5UREy7cn4yC4hlHuW87qDp2fEg3YQlZCETrkBbLqIgtAqlklyahRIH0hCzSUOI3YQlZCETrkBbLqIgtAqlklkBbLqIgtAqlkl.txt

function getLength() {
     //alert(.length);
     var fullPath = document.getElementById("myfile").value;
     if (fullPath) {
         var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
         var filename = fullPath.substring(startIndex);
         if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) {
             filename = filename.substring(1);
         }
         alert(filename.length);
     }
}

      

What do I expect?

I expect IE9 to warn text length like in Chrome and FireFox

What happens instead?

Firefox and chrome give me 230, however IE9 won't even let me download the file.

Is there a way for IE9 to recognize this file and warn the length of the filename like Chrome and Firefox?

+3


source to share


1 answer


Windows limits path length to 255 characters (file path + name, including extension and .

), + 3 extra characters forC:\

Source: http://vlaurie.com/computers2/Articles/filenames.htm

I run into this all the time trying to decompress large zip attachments.

IE9 makes it worse because it includes the full pathname for the file name for input elements file

, including opening "C: \".

Source: http://support.softartisans.com/kbview_892.aspx

So on windows the theoretical filename limit is 258 characters including C:\

. But when IE9 grabs this file, it shows the full path including C:\

, so the largest file name you can download in IE9 is 255 characters includingC:\

So for example this will NOT load



C: \ 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890axxx.txt

but it will

C: \ 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890a.txt

and Windows won't even let you name the file:

C: \ 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890axxx00000.txt

because it's too long.

Most likely your file was somewhere in that "magic range" greater than 255, so IE is not allowed, but less than 259, so it is still allowed by Windows. Firefox and Chrome don't care and don't make newer versions. IE.

There's IE9

nothing you can do about it.

+3


source







All Articles