Backend Development 2 min read

PHP scandir Function: List Files and Directories in a Specified Path

The PHP scandir function returns an array of filenames and sub‑directories from a given directory, optionally sorted in ascending or descending order, and can accept a stream context, providing FALSE on failure and generating a warning if the path is not a directory.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP scandir Function: List Files and Directories in a Specified Path

The PHP scandir function returns an array of files and directories contained in a specified directory.

Syntax: array scandir(string $directory[, int $sorting_order[, resource $context]])

Parameters :

directory : the directory to be scanned.

sorting_order : optional; default is alphabetical ascending. If set to 1, sorting is alphabetical descending.

context : optional stream context resource (see manual for details).

Return value : on success, an array of filenames; on failure, FALSE . If $directory is not a directory, FALSE is returned and a PHP E_WARNING is generated.

backendPHPfunctionfilesystemdirectoryscandir
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.