អនុកម្មវិធី PHP scandir()

ឧទាហរណ៍

ចង្អុលបង្ហាញរបស់តំបន់កាតព្វកិច្ច និងថតក្រុមមួយក្នុងតំបន់កាតព្វកិច្ច images:

<?php
$dir = "/images/";
// ដាក់លំដាប់តាមលំដាប់ - រដ្ឋបាលតាមលាបលើកដំបូង
$a = scandir($dir);
// Sort in descending order
$b = scandir($dir,1);
print_r($a);
print_r($b);
?>

Result:

Array
(
[0] => .
[1] => ..
[2] => cat.gif
[3] => dog.gif
[4] => horse.gif
[5] => myimages
)
Array
(
[0] => myimages
[1] => horse.gif
[2] => dog.gif
[3] => cat.gif
[4] => ..
[5] => .
)

Definition and Usage

The scandir() function returns an array of files and directories in the specified directory.

Syntax

scandir(directory,sorting_order,context);
Parameter Description
directory Required. Specifies the directory to be scanned.
sorting_order

Optional. Specifies the sorting order. The default is 0, which means sorting in alphabetical ascending order.

If set to SCANDIR_SORT_DESCENDING or 1, indicates sorting in alphabetical descending order.

If set to SCANDIR_SORT_NONE, returns unsorted results.

context Optional. Specifies the environment for the directory handle.context A set of options that modify the behavior of a directory stream.

Technical Details

Return Value:

Returns an array of files and directories if successful. Returns FALSE on failure.

If directory If not a directory, an E_WARNING level error is thrown.

PHP Version: 5.0+
PHP Update Log: PHP 5.4: New sorting_order Constants.