Thứ Tư, 17 tháng 11, 2010

How to Read all files name in a folder using php

Write the below code to read filse name from an particular folder.



function dirFiles($directry) {

$dir = dir($directry); //Open Directory

while (false!== ($file = $dir->read())) //Reads Directory

{

$extension = substr($file, strrpos($file, '.')); // Gets the File Extension

if($extension == ".xml" || $extension == ".csv" || $extension == ".php" |$extension == ".txt") // Extensions Allowed

$filesall[$file] = $file; // Store in Array

}

$dir->close(); // Close Directory

asort($filesall); // Sorts the Array

return $filesall;

}



$array = dirFiles('/home/your absolute directory/');



foreach ($array as $key => $file)

{

echo $file; // Display Images

echo '<br />';

}


Không có nhận xét nào:

Đăng nhận xét