tet3828 Posted February 2, 2008 Share Posted February 2, 2008 Quick question. I was reading through some functions in the php manual I am intrested in using the mkdir function for a project I am working on. The manual says it returns true if it succeeded and a false if it failed. This may be basic and I've prob even done it with other functions but... how can I check the value it returned? so far I have: mkdir ("TRAINING SESSION"); so what do I do now? if mkdir == false {return error} ??? Quote Link to comment https://forums.phpfreaks.com/topic/88995-true-or-false-returns-from-bools/ Share on other sites More sharing options...
Caesar Posted February 2, 2008 Share Posted February 2, 2008 <?php $dir_name = 'TRAINING_SESSION'; mkdir($dir_name); if(is_dir($dir_name)) { echo'Cool. It worked'; } else { echo'Negatory, my friend.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88995-true-or-false-returns-from-bools/#findComment-455778 Share on other sites More sharing options...
Caesar Posted February 2, 2008 Share Posted February 2, 2008 Also...I'm guessing for it to work...the directory you're throwing that folder into, must be writable. Haven't used the function in a long time. Quote Link to comment https://forums.phpfreaks.com/topic/88995-true-or-false-returns-from-bools/#findComment-455779 Share on other sites More sharing options...
Cep Posted February 2, 2008 Share Posted February 2, 2008 You could also assign the function to a variable then test the variable. $directory = mkdir($dir_name); if ($directory===true) { //do this } else { //do this } Quote Link to comment https://forums.phpfreaks.com/topic/88995-true-or-false-returns-from-bools/#findComment-455796 Share on other sites More sharing options...
trq Posted February 2, 2008 Share Posted February 2, 2008 You could also assign the function to a variable then test the variable. You can also simply test it as you use it. <?php if (mkdir ("TRAINING_SESSION")) { echo 'mkdir successfull'; } else { echo 'mkdir failed'; } ?> ps: Directories (just as files) should not have spaces in there names. Quote Link to comment https://forums.phpfreaks.com/topic/88995-true-or-false-returns-from-bools/#findComment-455814 Share on other sites More sharing options...
laffin Posted February 2, 2008 Share Posted February 2, 2008 yep, as thorpe suggests mkdir returns true or false. depending if it succeeded or not. so there is no need to use other functions (is_dir) to check if it succeeeded. since it returns a numeric, ya can use it as an expression (if,while,switch). you will find a lot of functions that return simple information like this, so is of great use. Quote Link to comment https://forums.phpfreaks.com/topic/88995-true-or-false-returns-from-bools/#findComment-455846 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.