Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check File size Before Uploading

Status
Not open for further replies.

NateBro

Programmer
Sep 1, 2004
233
US
hey, i'm not sure if i should put this in PERL or what, but i have a file up-loader and i wanted to make a progress bar, but i know you can't access the file client side, but i just noticed that myspace.com has a progress bar when you upload a picture. so how does it know the file size before its on the server, it has to be client side, so do i use Java, Active X or what?

Thanks agin for your time!
:)

Thanks,
Nate_Bro
 
[warning]Not for every client-side scripter's consumption[/warning]
[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 the form element control...
[tt]
<input name="x" type="file" onchange="doit(this.value)" />
[/tt]
It assumes jvm installed for moz, plus some security settings at least minimally seeking client consent.
 
Thanks! I'll check it out

Thanks,
Nate_Bro
 
hmmm... I'm not sure what i'm doing wrong here, I've only used ActiveX a few times, but i'm not sure about this. this is my final .htm document, is this right, or completely wrong?

Code:
<html>
<head>
<script type="text/javascript" language="javascript">
// [warning]Not for every client-side scripter's consumption[/warning]
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");
}
</script>
</head>
<body>
<input name="x" type="file" onchange="alert(this.value);doit(this.value)"/>
</body>
</html>

and if it helps i have PERL runing not ASP.

Thanks agin for your help!
 
you might also want to put this in there to..

Code:
  cuteLittleWindow.document.focus();
 
In ie, menu: Tools/Internet Options/Security/choose the security zone and Custom Level. Under radio button(s) of "Initialize and script ActiveX not marked as safe", select "prompt" button.
 
tsuji's code works for me here NateBro, are you still having problems?

The code uses ActiveX which means it will only be supported in Internet Explorer. It will not work in other browsers.


At my age I still learn something new every day, but I forget two others.
 
ya i was thinking it was my security settings but i enabled all ActiveX, also i tried using other codes from tutorials, and they didn't work ether, so i guess its just my bad, thanks again :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top