PHP read files in a directory _php tutorial

Source: Internet
Author: User
/* Purpose: Read the file under a directory */

The directory to read
$folder = "H:/temp";

Open Directory
$FP =opendir ($folder);

Read Catalogue
while (false!= $file =readdir ($fp))
{
List all files and remove '. ' and ' ... '
if ($file! = '. ' && $file! = ' ... ')
{
$file = "$folder/$file";
$file = "$file";

assigning values to arrays
$arr _file[]= $file;

}
}
Output results
if (Is_array ($arr _file))
{
while (list ($key, $value) =each ($arr _file))
{
echo "$key and $value
";
}

}

Close Directory

Closedir ($FP);

?>


----------------------
Read a file in a directory 2



/* Purpose: Read the file under a directory two */

function Listfiles ($dir)
{
Open Directory


$handle =opendir ($dir);

Read Catalogue

while (false!= ($file =readdir ($handle)))

{
List all files and remove '. ' and ' ... '

if ($file! = '. ') && $file! = ' ... ')

{

Whether the resulting file name is a directory

if (Is_dir ("$dir/$file"))

{
List files in directory

Listfiles ("$dir/$file");

}

Else

http://www.bkjia.com/PHPjc/631972.html www.bkjia.com true http://www.bkjia.com/PHPjc/631972.html techarticle PHP/* Purpose: Read the file in a directory *///directory to read $folder =h:/temp;//Open Directory $fp =opendir ($folder);//Read directory while (false!= $file = Readdir ($FP)) {//list ...

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