0

I have a form which takes a couple of text field inputs and then a folder path. Now before I submit the form I want to make sure that whatever the folder path the user specified is correct, if not print an error message.

Is there a way I can validate this in the same page before I submit the form?

I used javascript, but it doesnt seem to work as I expected. Thoughts/Suggestions ?

<script>
 function checkfolder()
 {
   var myObject;
   myObject = new ActiveXObject("Scripting.FileSystemObject");
   if(!myObject.FolderExists()){
     alert("Folder does not exist");
    }
  }
</script>
<form method=post action="some_file.php">
.
.
.

<input type="submit" name="submit" value="submit" onClick='checkFolder()'>
</form>
2
  • A folder path on the client? What's the use case? Commented Apr 28, 2012 at 0:14
  • Its a complicated use case. I wish I could explain it :| Commented Apr 28, 2012 at 0:24

2 Answers 2

1

You're not going to have much luck with this. PHP can't do this because it operates on the server and has no access to the user's computer. JavaScript will fail because browser prevent access to the file system with JavaScript for security reasons.

Sign up to request clarification or add additional context in comments.

5 Comments

To add to that... "Scripting.FileSystemObject" is only allowed in the context of a locally run .JS file (Semi-Windows Automation) or in the case of a HyperText Application, a web-based app technology that MS made in the late 90s and hasn't updated since.
What would be my second best choice ?
If possible, validate it after form submission.
PHP has a function that can validate if the directory exists. But will I lose my form data if I validate and redirect to actual page using header ??
@naveen the php function will see if the directory exists in the server. Why exactly you need to validate if the folder exists in the client machine? In java you can do this with an applet but needs to be signed and depends on the accept of the client user
0

You don't have any way of accessing the local data to validate its existence. Even if you do, it's considered really bad.

Instead of writing the file path (which I assume that's what you are doing), just make a javascript Browse file dialog like when you upload an image or file to Gmail. That kind. This ensures that it exists at least when you are trying to upload the file.

Whether the file actually gets deleted after you have selected the file, and before you submit it. It doesn't matter. If it doesn't exist, the upload will fail.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.