Try this if you can make out for yourself...
[tt]
function doit(fspec) {
var fsize;
if (window.ActiveXObject) {
fsize=(new ActiveXObject("scripting.filesystemobject")).getFile(fspec).size;
} else {
fsize=(new java.io.File(fspec)).length();
}
alert(fsize+" bytes");
}[/tt]
with calling config like this or expansion based on it.
[tt]
<input type="file" onchange="doit(this)" />
[/tt]
I clearly stated that I don't think that you can. But as your code doesn't work (in FF or IE), I'm yet to be convinced otherwise - but would be very happy to see a working solution that was cross-browser compatible.
Besides, accessing the INPUT element with type=FILE and its related file IS restricted in several ways due to security - which is what I noted above - hardly a 'web-pseudo-wisdom' ...
seriously tsuji, chill-out.
A smile is worth a thousand kind words. So smile, it's easy!
you need to chill out. tsuji has been an asset in the js forum for years. clearly, his code will not work in firefox, as active-x is IE only. his code will work with one minor change:
the OP asked a question in the javascript forum. while telling them it can't work is probably the safest answer, tsuji has provided a javascript solution (with a minor flaw).
*cLFlaVA
---------------------------- [tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]
Upon reading your full post Cory, I need to add that I am too ambitious to make it work on moz as well. That's how it is constructed. I suppose jvm installed and some moz security twist that most moz fans seem to ignore to my surprise. But I won't insist. Each one makes out what one can.
The code tsuji provided theoretically caters for both IE and non IE and doesn't work in either, with the object or the value passed to it.
Don't get me wrong, I'm not having a go at tsuji (even after his testing second post) - just correcting that somewhat accusing post and confirming what I meant. And I would be very interested to see a working solution.
Apologies if my last post came across in any way as stressed, it's been a long day.
Still... it doesn't work, and supposing that the vast majority of users (who are non-technical) will have just the right settings/config and software installed is presumptious to say the least.
But post back with any updates/corrections/ideas or even examples on the net that work - although I've never needed this particular feature, it would be nice to know.
And, guys... chill-out ;-) working together is much easier.
A smile is worth a thousand kind words. So smile, it's easy!
clearly, the *best* solution to this issue (for cross-browser compatability, and to ensure that javascript haters still have this work for them) would be to use the server-side code (php, asp, cfm, what-have-you).
*cLFlaVA
---------------------------- [tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]
I'd agree, but it would be nice for this to work for those that have javascript enabled - as an added pre-check.
Maybe it is just my testing, but I cannot get the code tsuji posted to work in either FF (1.5) or IE(6) - I changed the parameter to getFile to the value rather than the object when I first tested (which is the right param as noted above) but it didn't work - just security errors.
I know this should work when run as a normal script (outside of the browser context) but when in the secure context of the browser - is it likely to work ? certainly not the full functionality of the filesystemobject as that would allow any website to compromise any visitors computer.
A smile is worth a thousand kind words. So smile, it's easy!
probably your security settings. when i copied/pasted his code and tried it in IE, i got a warning about activex which i accepted. the application then prompted me with the size of the file i chose.
*cLFlaVA
---------------------------- [tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]
and, to be honest, worked perfectly in FF as well.
*cLFlaVA
---------------------------- [tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]
Still cannot get it to work in FF 1.5 (java enabled) maybe it's due to it being a beta - what version are you running? But am just trawling through the huge about:config settings list to see if I can identify if any tweaks could be preventing it - if it works for you it will probably work in other cases - with a few tweaks to configuration.
So, as it does work it's an option, though not a reliable one. Star for tsuji for the code.
A smile is worth a thousand kind words. So smile, it's easy!
*cLFlaVA
---------------------------- [tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.