Easy Tutorial
❮ Func Http Headers Sent Func Misc Connection Timeout ❯

PHP scandir() Function

PHP Directory Reference Manual

Example

List files and directories inside the images directory:

Result:


Definition and Usage

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


Syntax

Parameter Description
directory Required. Specifies the directory to be scanned.
sorting_order Optional. Specifies the sorting order. Default is 0, which means ascending alphabetical order. If set to SCANDIR_SORT_DESCENDING or 1, it means descending alphabetical order. If set to SCANDIR_SORT_NONE, the result is returned unsorted.
context Optional. Specifies the context of the directory handle. Context is a set of options that can modify the directory stream's behavior.

Technical Details

Return Value: Returns an array of files and directories on success. Returns FALSE on failure. Throws an E_WARNING level error if directory is not a directory.
PHP Version: 5.0+
--- ---
PHP Changelog: PHP 5.4: Added sorting_order constants.
--- ---

❮ Func Http Headers Sent Func Misc Connection Timeout ❯