SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check file size with javascript

    I am using this code of checking the file size of uploaded file, it is working in IE only, not firefox and other browsers:

    Code:
       var myFSO = new ActiveXObject("Scripting.FileSystemObject");	
       var filepath = document.upload.image1.value;
       var thefile = myFSO.getFile(filepath);
       var size = thefile.size;
       alert(size + " bytes");
       return false;
    I googled over that issue and found that ActiveXObject does't work with firefox.

    Kindly help.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use something else. Like Java, Flash, or Silverlight. Javascript gets little to no access to the filesystem.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    JavaScript doesn't know what a file is. IE supports JScript rather than JavaScript and has a few additional features intended for intranet use where the security issues those extra features create are not a concern.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    You need to use something else. Like Java, Flash, or Silverlight. Javascript gets little to no access to the filesystem.
    A plugin is the best option, since it will be cross browser compatible.

    However, if you want to target IE and Firefox, for Firefox you can use XUL which can do File IO via XPCOM.
    https://developer.mozilla.org/en/Cod...pets/File_I//O

    Example:
    http://www.captain.at/programming/xul/
    Fiji Web Design - Enterprise Web Design

  5. #5
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <html>
    <head>
    <script language="JavaScript">
    function A()
    {
    var oas = new ActiveXObject("Scripting.FileSystemObject");
    var d = document.a.b.value;
    var e = oas.getFile(d);
    var f = e.size;
    alert(f + " bytes");
    }
    </script>
    </head>
    <body>
    <form name="a">
    <input type="file" name="b">
    <input type="button" name="c" value="SIZE" onClick="A();">
    </form>
    </body>
    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •