A program in which PHP gets all the files in the directory and saves the results to an array

Source: Internet
Author: User
Tags array

There are times when you are working on a file that needs to be processed in batches in a directory, this time we need to find all the eligible files in the directory and save them to a result set, and then make it easy to batch, usually by saving it to an array and then looping through it, and then documenting the process.

<?php
//php gets all the files in the directory and saves the results to the array
foreach (Glob (". *") as $d) {
	$tmp =explode (".", $d);
	$k =end ($tmp);
	If it is a file and the file with the suffix filename jpg png (
	is_file ($d) &&in_array ($k, array ("JPG", "png")) {
		$files []= $d;
	}
}
echo "<pre>";p Rint_r ($files);

The source code above is to list all files with the suffix jpg png in the current directory, save the results in an array and print them out, and the results of this test are printed as follows:

Articles that you may be interested in

  • PHP generates a continuous number (letter) Array function range () analysis, PHP lottery program function
  • A function of PHP to read directories and tables to display files in a directory
  • How PHP clears HTML formatting and removes spaces from text and then intercepts text
  • PHP Analysis file header information to determine the type of upload file
  • PHP gets the method for each month over a period of time, returning an array of these months
  • PHP Delete directory and all files in directory
  • PHP implementation to instantly output the results to the browser
  • PHP Gets the remote picture and downloads it to the local


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.