"Seeking ideas" PHP directory scanning, the best way to prevent the death cycle of the idea? How to fix it

Source: Internet
Author: User
"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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.