phppup Posted Wednesday at 04:34 AM Share Posted Wednesday at 04:34 AM I thought this made sense, but it wouldn't work until I removed lines that I thought would provide extra validation: $dir = 'rootFolder'; $directories = scandir($dir); foreach($directories as $directory){ if($directory=='.' or $directory=='..' ){ echo 'dot'; }else{ if(is_dir($directory)) echo '<strong>'.$directory .'</strong> <br>'; $filePath = scandir($directory); foreach($filePath as $subDir){ if($subDir=='.' or $subDir=='..' ){ echo 'dot2 <br>'; }else { // if (is_file($subDir)) { //Only provided PHP files but NO IMAGES echo $subDir . "<br>"; } } // } } } } I'm just feeling down one level of a director to see what I've get. It seemed like a simple exercise until I tried to list the files. Obviously, of it's not a directory it MUST be a file, but why did quantifying it as a file not recognize my files as a file?? Quote Link to comment https://forums.phpfreaks.com/topic/329643-why-is_file-isnt-seeing-files/ Share on other sites More sharing options...
mac_gyver Posted Wednesday at 06:07 AM Share Posted Wednesday at 06:07 AM 1 hour ago, phppup said: if(is_dir($directory)) the above line is missing any { }, so the only line of code that gets executed for an is_dir() is the - echo '<strong>'.$directory .'</strong> <br>'; all the rest of the lines get executed regardless of what $directory is. i recommend that you always format your code so that you can see when it is actually doing. 1 Quote Link to comment https://forums.phpfreaks.com/topic/329643-why-is_file-isnt-seeing-files/#findComment-1656244 Share on other sites More sharing options...
Solution phppup Posted Wednesday at 11:55 AM Author Solution Share Posted Wednesday at 11:55 AM @mac_gyver yes, I had discovered that, but it wasn't the actual fix. The real issue was that my test for is_file was flawed; it didn't drill down to actually test the specified file. if (is_file($subDir)) { //needed to become if (is_file($directory.'/'.$subDir)) { After both adjustments, everything is running better than expected! Quote Link to comment https://forums.phpfreaks.com/topic/329643-why-is_file-isnt-seeing-files/#findComment-1656269 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.