FileUpload file validation through JavaScript

prashantSum's Avatar
Contributor
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.
0
prashantSum's Avatar
Contributor
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'.
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
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");
0
prashantSum's Avatar
Contributor
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?
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Its embedded in IE & Firefox, you don't require anything extra for that!
0
prashantSum's Avatar
Contributor
thanks for reply pradeep
0
yasa83_jsm's Avatar, Join Date: Feb 2008
Light Poster
hi am getting undefined ActiveXObject. can u please help me out on this.
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
This only works in Internet Explorer. What browser are you using?
0
yasa83_jsm's Avatar, Join Date: Feb 2008
Light Poster
in firefox.. i even tried with IE. that too gave me this mgs."Automation server can't create object".
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
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'.