no client-side code to check if a file path exists?

Discussion in 'Javascript' started by Matt, Oct 15, 2004.

  1. Matt

    Matt Guest

    <input type="file" size=50"> will produce the browse button
    and browse text box.

    The user can either select the file from browse button,
    or enter a path in browse text box manually. My question is if
    there are any client-side code to check if the path exists
    in this case? My understanding is that no client-side
    solution to this problem.

    please advise. thanks!!
    Matt, Oct 15, 2004
    #1
    1. Advertising

  2. Matt

    Randy Webb Guest

    Matt wrote:

    > <input type="file" size=50"> will produce the browse button
    > and browse text box.
    >
    > The user can either select the file from browse button,
    > or enter a path in browse text box manually. My question is if
    > there are any client-side code to check if the path exists
    > in this case? My understanding is that no client-side
    > solution to this problem.


    Your understanding is correct.

    If they type it in the browse box though, and its an invalid path, then
    the OS/browser won't allow the browse window to be closed. If they type
    it into the file input box though, it won't respond until it attempts to
    upload the file. And then, the browser/OS will notify the user. So what
    you are trying to do is duplicate functionality that is already built-in
    to the browser/OS

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Randy Webb, Oct 15, 2004
    #2
    1. Advertising

  3. Matt

    McKirahan Guest

    "Matt" <> wrote in message
    news:...
    > <input type="file" size=50"> will produce the browse button
    > and browse text box.
    >
    > The user can either select the file from browse button,
    > or enter a path in browse text box manually. My question is if
    > there are any client-side code to check if the path exists
    > in this case? My understanding is that no client-side
    > solution to this problem.
    >
    > please advise. thanks!!


    This does what (I think) you want but it issues a security warning.

    <html>
    <head>
    <title>typefile.htm</title>
    <script type="text/javascript">
    function typefile() {
    var form = document.forms[0];
    var file = form.what.value;
    var fold = file.substr(0,file.lastIndexOf("\\"));
    window.status = file + " : " + fold;
    var oFSO = new ActiveXObject("Scripting.FileSystemObject")
    if (!oFSO.FolderExists(fold)) {
    alert("Folder does not exist!");
    } else if (!oFSO.FileExists(file)) {
    alert("File does not exist!");
    }
    }
    </script>
    </head>
    <body>
    <form>
    <input type="file" name="what" size=50" onchange="typefile()">
    </form>
    </body>
    </html>
    McKirahan, Oct 15, 2004
    #3
  4. Matt

    McKirahan Guest

    [snip]

    Typo!

    <input type="file" name="what" size="50" onchange="typefile()">
    McKirahan, Oct 15, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    2
    Views:
    2,333
    brucie
    Oct 16, 2004
  2. Ulf Meinhardt
    Replies:
    8
    Views:
    6,118
  3. Alessandro
    Replies:
    5
    Views:
    556
    Alessandro
    Sep 27, 2010
  4. Matt
    Replies:
    3
    Views:
    132
    Grant Wagner
    Sep 17, 2004
  5. Matt
    Replies:
    1
    Views:
    87
    Randy Webb
    Oct 20, 2004
Loading...

Share This Page