PHP - Is_dir()
I have the following code... While(($file = readdir($handle)) !== FALSE){ if(is_dir($file))){ echo "$file - Directory<br>"; }else{ echo "$file - Not Directory<br>"; } }
And I have the following files/folders... 2019-holiday-party _photos _thumbnails xxx IMG_2205.png
I get these results... . - Directory .. - Directory _photos - Not Directory _thumbnails - Not Directory IMG_2205.png - Not Directory xxx - Not Directory
Why do the directories "_photos" and "_thumbnails" and "xxx" get reported as "Not Directory"???
Also, where does the "." (dot) and ".." (dot dot) come from?? Edited December 23, 2019 by SaranacLake Similar TutorialsI have approximately 50k-100k files in a directory. I'm running a script to check if any of the files are being used by the DB, if not then delete them. The problem is that I have made a quick test on a directory of just 1k files and it dies. Is there a way to optimize it? I know the script works, it's just that it takes too long to run. Even with just 1k files. And I'm pretty sure is the is_dir that's taking its sweet time. Any ideas? <?php require_once 'db_connect.php'; $default_dir = "storage/2011/"; if(!($dp = opendir($default_dir))) die("Cannot open $default_dir."); while($file = readdir($dp)) { if(is_dir($file)) { continue; } else if($file != '.' && $file != '..') { $query = "SELECT * FROM images Where filename = '".$file."' OR thumbname = '".$file."'"; $dbResult = mysql_query($query); $num_rows = mysql_num_rows($dbResult); if ($num_rows == 0){ unlink($default_dir.$file); echo $file."<br />"; } } } closedir($dp); ?> |