Reputation: 687
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>
Upvotes: 0
Views: 697
Reputation: 17040
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.
Upvotes: 0
Reputation: 219804
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.
Upvotes: 1