PHP gets all the filenames in the directory and how to determine the file and directory

Source: Internet
Author: User
    1. Open the directory under the current directory under Pic subdirectory common.
    2. $handler = Opendir (' Pic/common ');
Copy Code

2. Loop through all the files in the directory

    1. /* Where $filename = Readdir ($handler)
    2. The read file name is assigned to $filename each time the loop is passed, $filename!== false.
    3. Be sure to use!==, because if a file name is called ' 0′ ', or if some is considered false by the system, the loop will stop with! =
    4. */
    5. while (($filename = Readdir ($handler))!== false)
    6. {
    7. Skip to the Linux directory with the name '. ' and ' ... ' of the file
    8. if ($filename! = "." && $filename! = "...")
    9. {
    10. Output file name
    11. echo $filename;
    12. }
    13. }
Copy Code

3. Close the Directory

    1. Closedir ($handler);
Copy Code

Two, PHP judgment file and directory function code:

    1. Check whether the target object logo.jpg under the parent directory is a file.
    2. $checkResult = Is_file ('.. /logo.jpg ');
Copy Code

Description: If the target object is a file, the system returns TRUE, otherwise false is returned.

Code:

    1. Check whether the target object logo.jpg under the parent directory is a directory.
    2. $checkResult = Is_dir ('.. /logo.jpg ');
Copy Code

Description: Returns False if the target object is a directory system that returns TRUE.

  • Related Article

    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.