PDA

View Full Version : check file


shikha
04-25-2003, 06:47 AM
hi friends,

can anyone tell me how to check the whether file exists on client pc or not in javascript.

thanks in advance

regards
shikha

glenngv
04-25-2003, 07:07 AM
javascript can't access files on the client.

shikha
04-25-2003, 07:18 AM
there is surely some method becoz when javascript allow us to select the file from the client pc by using

<input type=file........>

then there must be a way to perform some function on that.
ok can u tell me can we check the length of file selected.

shikha

liorean
04-25-2003, 08:14 AM
Nope - because of security reasons, most browsers doesn't handle the file fields after you've edited them using javascript - they must be set by the user.

Java applets and ActiveX controls can't do this either. Plugins could, as they reside on the client computer and have full rights, but I find it unlikely they would allow such actions from a website.

rsci
04-25-2003, 09:04 PM
Actually you could do it with ActiveX. However most users, with a properly configured browser will receive a security alert.

Some general information is located here:
http://www.tutorial-web.com/asp/fso/filesystem.asp?property=FileExists

Just port the code to JS.

liorean
04-25-2003, 09:28 PM
Actually, you can do the same in both JScript and Java - but not without the question being asked.

shikha
04-28-2003, 05:38 AM
i used ActiveXobject to check the file but the server is not able to throw the page contain this object.My code is:


function check() {

var imgstr = document.test.checkfile.value;
var filestr=imgstr.replace(/^\s+/,'').replace(/\s+$/,'');
var len=filestr.indexOf("\\");

if ((len==0)||(len==1))
{
alert("Drive in which file is searched must be mentioned");
exit;
}
try
{
var fso = new ActiveXObject('Scripting.FileSystemObject');
var fs=fso.getFile(filestr);
alert("File found");
}
catch(Exception)
{
alert("File not found");
}
}



shikha

rsci
04-28-2003, 04:30 PM
I don't quite understand your comment:
to check the file but the server is not able to throw the page contain this object.
What exactly do you mean? What are you trying to do?

shikha
04-29-2003, 08:20 AM
i mean to say that i made a page containing the code as shown above.but when i request to the server to throw this page it is giving the error as this page is containing the activexobject.

if i simply run this page on system it is running .


shikha

rsci
04-29-2003, 05:59 PM
That is the warning message that was mentioned earlier in this post. Unless the user has a 'loosely' configured broswer or the script is signed, there will be a warning message.

shikha
04-30-2003, 07:33 AM
no i mean to say that the when the user request for that page from the server ,the server is not throwing the page .it is not giving the warning message.but simply it is not showing the page.



shikha

rsci
05-04-2003, 01:29 PM
Could you post the code or send a link to the page?

shikha
05-05-2003, 01:21 PM
here the code:

<HTML>
<HEAD>
<TITLE>Check whether file exists or not</TITLE>
<SCRIPT language="JAVASCRIPT">

function check() {

var imgstr = document.test.checkfile.value;
var filestr=imgstr.replace(/^\s+/,'').replace(/\s+$/,'');
var len=filestr.indexOf("\\");

if ((len==0)||(len==1))
{
alert("Drive in which file is searched must be mentioned");
return;
}
try
{
var fso = new ActiveXObject('Scripting.FileSystemObject');
var fs=fso.getFile(filestr);
alert("File found");
}
catch(Exception)
{
alert("File not found");
}
}
</SCRIPT>
</HEAD>
<BODY >
<FORM name="test" method="get" >
<input type="file" name="checkfile" size=30 >
<br>
<br>
<input type="button" name="val" value="validate" onclick="javascript:check();">

</FORM>
</BODY>
</HTML>

shikha
05-09-2003, 12:18 PM
activeXobject is not supported by apache tomact server.So can anyone tell me any other solution of this


Regards
shikha

brothercake
05-09-2003, 12:38 PM
Either do the whole thing in PHP which Apache can run, or do the whole thing with ActiveX using a microsoft server platform - IIS.

shikha
05-09-2003, 12:54 PM
can u tell me what is PHP??

brothercake
05-09-2003, 12:59 PM
PHP is a server-side scripting language. php.net (http://www.php.net) is a good place to start, and of course we have a forum devoted to it here :)

shikha
05-09-2003, 02:14 PM
but i want to check on the client side not on the server side

brothercake
05-11-2003, 08:38 PM
Then you're out of luck I'm afraid - MS ActiveX is the only client-side method for reading files.

Unless of course the file you want to read is an XML document - in which case there are standard methods for that which work in IE6 and mozilla browsers.

shikha
05-12-2003, 08:43 AM
can u tell me any other by which i can put a validation so that user can enter only the correct file name.and it is checked only on client side.

brothercake
05-12-2003, 12:40 PM
There is no other way; what you want is impossible.

shikha
05-12-2003, 03:16 PM
can i do it with the help of vbscript.if yes then plz do tell me the sol

brothercake
05-12-2003, 04:02 PM
Yes you can do it with VBScript - but VBScript in client-side pages which accesses local files ... is an ActiveX control.

Please accept this - you have the following choices:

1 - ActiveX
2 - server-side scripting