townclown Posted June 11, 2008 Share Posted June 11, 2008 Hi, I am having an irritating issue when trying to check if exists/create a directory. Here is the code i am using: $dirname = "HE"; if (!is_dir("{$dirname}")) { print("Error: The directory <b>({$dirname})</b> doesn't exist"); mkdir("{$dirname}", 0777); print( " The directory {$dirname} has been successfully created."); } else { print "Directory Already Exists"; //more stuff to go in here } If the directory doesn't exist, it runs through the motions and creates it perfectly. My problem comes if the directory does exist, the browser opens the index of that directory instead of staying on the .php page that is running this script so anything in the else part( or anything that comes after the if statement) doesn't run. Any ideas? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/109723-solved-php-5-creating-directory-issue/ Share on other sites More sharing options...
Vizor Posted June 11, 2008 Share Posted June 11, 2008 Try using file_exists() instead of is_dir() also it might be a problem with whatever code is in your else block unless you're having problems with that basic script that you posted. Link to comment https://forums.phpfreaks.com/topic/109723-solved-php-5-creating-directory-issue/#findComment-563027 Share on other sites More sharing options...
townclown Posted June 11, 2008 Author Share Posted June 11, 2008 Thanks, will try that; there is currently nothing in the else block other than the print. Link to comment https://forums.phpfreaks.com/topic/109723-solved-php-5-creating-directory-issue/#findComment-563029 Share on other sites More sharing options...
townclown Posted June 11, 2008 Author Share Posted June 11, 2008 Same outcome with file_exists() Link to comment https://forums.phpfreaks.com/topic/109723-solved-php-5-creating-directory-issue/#findComment-563030 Share on other sites More sharing options...
townclown Posted June 11, 2008 Author Share Posted June 11, 2008 Was an apache server setting btw Link to comment https://forums.phpfreaks.com/topic/109723-solved-php-5-creating-directory-issue/#findComment-563060 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.