Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   FileUpload file validation through JavaScript (http://www.go4expert.com/forums/fileupload-file-validation-javascript-t1069/)

prashantSum 26Jul2006 20:09

FileUpload file validation through JavaScript
 
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.

prashantSum 27Jul2006 11:22

Re: FileUpload file validation through JavaScript
 
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'.

pradeep 27Jul2006 14:21

Re: FileUpload file validation through JavaScript
 
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");


prashantSum 27Jul2006 15:50

Re: FileUpload file validation through JavaScript
 
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?

pradeep 27Jul2006 17:37

Re: FileUpload file validation through JavaScript
 
Its embedded in IE & Firefox, you don't require anything extra for that!

prashantSum 27Jul2006 18:34

Re: FileUpload file validation through JavaScript
 
thanks for reply pradeep

yasa83_jsm 19Feb2008 11:39

Re: FileUpload file validation through JavaScript
 
hi am getting undefined ActiveXObject. can u please help me out on this.

pradeep 19Feb2008 12:06

Re: FileUpload file validation through JavaScript
 
This only works in Internet Explorer. What browser are you using?

yasa83_jsm 19Feb2008 13:10

Re: FileUpload file validation through JavaScript
 
in firefox.. i even tried with IE. that too gave me this mgs."Automation server can't create object".

pradeep 19Feb2008 18:27

Re: FileUpload file validation through JavaScript
 
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'.


All times are GMT +5.5. The time now is 00:27.