FileUpload file validation through JavaScript

Discussion in 'JavaScript and AJAX' started by prashantSum, Jul 26, 2006.

  1. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,
    When we try to upload file through <input type ='file' />, it does not check whether the file really exists on the local file system, even if we give some arbitrary value like 'C:\asdf', it will upload it with 'asdf' as file name with no content.

    So is there any way to check on the client side with java script (I think we can do it with ActiveX Control but I want to know whether is it possible through JavaScript) whether the file really exists on the client side local system, so that if it is not present I can stop sending the request to the server.
     
  2. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    Sorry for posting this thread multiple times...

    actually when I posted it in 'HTML/DHTML/CSS - JavaScript/VBScript' in the 'forums' section, not in the 'queries and discussions', I could not see my post in the forums immediately, so I just got worried and posted it repeatedly..., then 4th time I posted it in 'queries and discussions'.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Yes! It's possible with JavaScript's FileSystem Object. Here's an example below:

    Code:
    var fso = new ActiveXObject("Scripting.FileSystemObject");
     fileBool = fso.FileExists("d:\\old.txt");
     
  4. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    thanks for the reply pradeep,

    the code is working, but I have a doubt

    what is ActiveXObject ? does it comes automatically or embedded with IE,

    and if this is an ActiveX Object then the code is not pure JavaScript I think?
     
  5. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Its embedded in IE & Firefox, you don't require anything extra for that!
     
  6. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    thanks for reply pradeep
     
  7. yasa83_jsm

    yasa83_jsm New Member

    Joined:
    Feb 19, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software Engg
    Location:
    chennai
    hi am getting undefined ActiveXObject. can u please help me out on this.
     
  8. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    This only works in Internet Explorer. What browser are you using?
     
  9. yasa83_jsm

    yasa83_jsm New Member

    Joined:
    Feb 19, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software Engg
    Location:
    chennai
    in firefox.. i even tried with IE. that too gave me this mgs."Automation server can't create object".
     
  10. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    You'll need to change the security settings for the zone the page/website is in, goto Tools -> Internet Options, the select Security tab, click on Custom level, location 'Run ActiveX controls and plug-ins' select either 'prompt' or 'enable'.
     

Share This Page

  1. 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.
    Dismiss Notice