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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPFilesystemdirectoryscandir
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

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.