Link to home
Start Free TrialLog in
Avatar of Pauliostro
Pauliostro

asked on

Check if directory exists before creating

Hi,

I have got a php script that runs perfectly to add/delete directories on a web server.  What i am after i think can be done some how with javascript.

I have a text field in a form, and what i would like to happen is for when a user starts typing in a name of a folder to create i need it to display back on screen (underneath text field for example) whether if directory exist or not.  It would only need to check 1 directory to see if a the new directory name exists when being entered.  In this case for my purpose it is the previous directory to where the script would work... so '../'

I hope some one can shine some light on this.

Many thanks
Pauliostro
Avatar of aescnt
aescnt

The existence of a directory has to be checked through PHP. The PHP function you're looking for is `is_dir()`.

Then you can have a "check for this directory" submit button which submits to a PHP script with the directory-checking logic, and redraw the form with text underneath the text field which would indicate the existence of the directory.

An alternate solution would be to use an XMLHTTPRequest (bound to onblur of the text field) to call a PHP script which would indicate if the directory does or doesn't exist. Then, use JS to change the text "underneath the text field."
Avatar of Pauliostro

ASKER

Hi Aescnt,

Thanks for your reply.  I like the 2nd option you have mentioned (XMLHTTPRequest).  Unfortunately its a bit out of my expertise, are you able to show me the code of how to do this or somewhere where i could find out about how to implement something like this.

Many thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of aescnt
aescnt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
aescnt, you are a living champion.  Thanks so much!!!!!!

Script works perfect...  thank you.... thank you... thank you....