FileUpload file validation through JavaScript

Contributor
26Jul2006,20:09   #1
prashantSum's Avatar
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.
Contributor
27Jul2006,11:22   #2
prashantSum's Avatar
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'.
Team Leader
27Jul2006,14:21   #3
pradeep's Avatar
Yes! It's possible with JavaScript's FileSystem Object. Here's an example below:

Code: JavaScript
var fso = new ActiveXObject("Scripting.FileSystemObject");
 fileBool = fso.FileExists("d:\\old.txt");
Contributor
27Jul2006,15:50   #4
prashantSum's Avatar
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?
Team Leader
27Jul2006,17:37   #5
pradeep's Avatar
Its embedded in IE & Firefox, you don't require anything extra for that!
Contributor
27Jul2006,18:34   #6
prashantSum's Avatar
thanks for reply pradeep
Light Poster
19Feb2008,11:39   #7
yasa83_jsm's Avatar
hi am getting undefined ActiveXObject. can u please help me out on this.
Team Leader
19Feb2008,12:06   #8
pradeep's Avatar
This only works in Internet Explorer. What browser are you using?
Light Poster
19Feb2008,13:10   #9
yasa83_jsm's Avatar
in firefox.. i even tried with IE. that too gave me this mgs."Automation server can't create object".
Team Leader
19Feb2008,18:27   #10
pradeep's Avatar
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'.