"Seeking ideas" PHP directory scanning, the best way to prevent the death cycle of the idea?
PHP Scan a folder to prevent the idea of a dead loop.
There are only two ways to think of yourself now.
1, while the scan goes down if it touches the directory to continue while. Easy to crash stuck
2, level Scan, scan one layer and save the directory address to the record file. Then extract the directory address from the saved record file and scan one layer at a time. However, if there are too many directories, it is easy to crash.
Is there a better idea?
Directory Scan PHP Opendir
Share to:
------Solution--------------------
You can use an iterator.
Example
$ite =new Recursivedirectoryiterator ("./");
$bytestotal = 0;
$nbfiles = 0;
foreach (New Recursiveiteratoriterator ($ite) as $filename = + $cur) {
$filesize = $cur->getsize ();
$bytestotal + = $filesize;
$nbfiles + +;
echo "$filename = $filesize \ n";
}
$bytestotal =number_format ($bytestotal);
echo "Total: $nbfiles files, $bytestotal bytes\n";
------Solution--------------------
FileSystem, can this thing solve your problem?
------Solution--------------------
SPL has helped you solve this problem, code to see #
------Solution--------------------
1 Floor code collection, and learned something.
------Solution--------------------
Top Posts Collection ~ ~
------Solution--------------------
Direct use of extensions
Directories