/    Sign up×
Community /Pin to ProfileBookmark

File size control using JavaScript

Hello JavaScript masters.

I have a formmail script that allow users to upload certain files (You can only get to the form after authencating). Some times the files gets pretty big. So, I would like to limit the file size on the client-end rather than the backend wasting resources. Is this possible using JavaScript? Also, is it possible to use JavaScript to validate their mime type in the client-end as well.

Thanks.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Alien_ManSep 06.2003 — Not sure if this is what you are looking for or not but it's the first thing that came to mind. You will however have to make a change to the code. mytest.txt will have to be replaced with a variable name that will be == to the file being uploaded.

<script type=”text/jscript” language=”JScript”>

<!--

function get()

{

var myObject, f;

// Create an instance of the FileSystemObject.

myObject = new ActiveXObject(“Scripting.FileSystemObject”);

f = myObject.GetFile(“c:tmpmyTest.txt”);

alert(“The file size is: “ + f.Size);

}

//-->

</script>
Copy linkTweet thisAlerts:
@jennAshtonauthorSep 08.2003 — Thanks Alien man. I will try it out and let you know.

Jenn
Copy linkTweet thisAlerts:
@Alien_ManSep 11.2003 — Your welcome just hope it was what you were looking for.
×

Success!

Help @jennAshton spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...