phpknight Posted August 6, 2007 Share Posted August 6, 2007 I have a question about the php mkdir() function. The docs say it returns TRUE on SUCCESS and FALSE on FAILURE. However, if you call this function on a directory that already exists, does it a) return true or false, and more importantly b) does it erase the current directory contents or leave it untouched? I understand that is_dir would likely be called, too, but I need to know if files would be erased in case some call ever got through the cracks. Quote Link to comment https://forums.phpfreaks.com/topic/63616-solved-mkdir-question/ Share on other sites More sharing options...
tarun Posted August 6, 2007 Share Posted August 6, 2007 I Would Have Thought That I Would Just Produce An Error (Return False) And Leave The Directory In Question Untouched Maybe You Could Just Do A Simple Test? ThanX, Tarun Quote Link to comment https://forums.phpfreaks.com/topic/63616-solved-mkdir-question/#findComment-317015 Share on other sites More sharing options...
phpknight Posted August 6, 2007 Author Share Posted August 6, 2007 That is what I am thinking too. I am almost afraid to do a test in case I erase something important on the server. Quote Link to comment https://forums.phpfreaks.com/topic/63616-solved-mkdir-question/#findComment-317022 Share on other sites More sharing options...
tarun Posted August 6, 2007 Share Posted August 6, 2007 I Would Do A Test Right Now But Im Going To Go Offline After This Message I Suggest That You Just Create A Test Directroy Named "testdir" And Put Some Blank TXT Files In It And Then Execute The PHP Script Of Whats Described Above Okay Bye, Tarun Quote Link to comment https://forums.phpfreaks.com/topic/63616-solved-mkdir-question/#findComment-317029 Share on other sites More sharing options...
Fadion Posted August 6, 2007 Share Posted August 6, 2007 I just did a test an it is turning '0' when a directory exists and also a warning 'Warning: mkdir() [function.mkdir]: File exists in blah blah'. Anyways just to be sure and surpress error messages u can use file_exists() to check if the directory exists or not, but in each case it will not delete a directory and all its files and create a blank one. Quote Link to comment https://forums.phpfreaks.com/topic/63616-solved-mkdir-question/#findComment-317064 Share on other sites More sharing options...
Daniel0 Posted August 6, 2007 Share Posted August 6, 2007 <?php mkdir('test'); mkdir('test'); ?> Warning: mkdir() [function.mkdir]: File exists in /var/www/test.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/63616-solved-mkdir-question/#findComment-317065 Share on other sites More sharing options...
phpknight Posted August 7, 2007 Author Share Posted August 7, 2007 Great. Thanks for the tests you guys. Quote Link to comment https://forums.phpfreaks.com/topic/63616-solved-mkdir-question/#findComment-317089 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.