A2xA Posted January 31, 2008 Share Posted January 31, 2008 I have a script that makes a game hub for a member. It is using mkdir and then chmodding it. If the folder already exists then it gives me this error: Warning: mkdir() [function.mkdir]: File exists in "SHOWS MY DIRECTORY" on line 6 This is an ugly/bad error message + it isn't good for security because it shows my file directorys. If someone could tell me how to fix this I would be grateful. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/88796-solved-if-folder-already-exists-then-display-error-message/ Share on other sites More sharing options...
pocobueno1388 Posted January 31, 2008 Share Posted January 31, 2008 Look at the file_exists() function. Quote Link to comment https://forums.phpfreaks.com/topic/88796-solved-if-folder-already-exists-then-display-error-message/#findComment-454773 Share on other sites More sharing options...
kenrbnsn Posted January 31, 2008 Share Posted January 31, 2008 Use the function file_exists() to check if the directory exists before trying to create it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/88796-solved-if-folder-already-exists-then-display-error-message/#findComment-454774 Share on other sites More sharing options...
A2xA Posted January 31, 2008 Author Share Posted January 31, 2008 thanks! That seems to be what I was looking for Quote Link to comment https://forums.phpfreaks.com/topic/88796-solved-if-folder-already-exists-then-display-error-message/#findComment-454782 Share on other sites More sharing options...
A2xA Posted January 31, 2008 Author Share Posted January 31, 2008 wait, this only tells them that it already exists and dosen't prevent them from overwriting it. Is there any way to do both? if (file_exists($dir)) { echo "The hub $dir exists already"; } else { echo "Hubs Sucessfully Added, Your Hub ID is "; echo "$dir"; } Quote Link to comment https://forums.phpfreaks.com/topic/88796-solved-if-folder-already-exists-then-display-error-message/#findComment-454797 Share on other sites More sharing options...
pocobueno1388 Posted January 31, 2008 Share Posted January 31, 2008 Only put the code to create the file between the else statement brackets. <?php if (file_exists($dir)) { echo "The hub $dir exists already"; } else { //Put code to create file here echo "Hubs Sucessfully Added, Your Hub ID is "; echo "$dir"; } Quote Link to comment https://forums.phpfreaks.com/topic/88796-solved-if-folder-already-exists-then-display-error-message/#findComment-454803 Share on other sites More sharing options...
A2xA Posted January 31, 2008 Author Share Posted January 31, 2008 Wow, That's a main thing I can use for a bunch of stuff. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/88796-solved-if-folder-already-exists-then-display-error-message/#findComment-454820 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.