PHP gets the file name of all files under the specified folder

Source: Internet
Author: User
 
  Read ()) {if ($file! = '. ') && $file! = ' ... ') {Searchdir ($path. ') /'. $file, $data); }} $DP->close (); } if (Is_file ($path)) {$data []= $path;}} function Getdir ($dir) {$data =array (); Searchdir ($dir, $data); return $data;}? >

After the method executes, an array of file names is returned, and the output is traversed:

$list =getdir (' image '); for ($i =0; $i
 
  
'; }

Output Result:


From the way can be seen that the file name contains the path we specified, if only to get the file name, only need to Getdir ($dir) with a for loop to handle it,
Add the following code to the return before you can:

for ($i =0; $i 
   
   
Also if your file name is in Chinese and is garbled, change the encoding to gb2312.

The above describes the PHP get the file name of all the files under the specified folder, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.