PHP scandir() Function

PHP rewinddir() Function
PHP readdir() Function

In this article, you will learn how to get all the files and subdirectories in a directory in PHP. The scandir() function in PHP returns an array of files and directories of the specified directory.

what is the syntax of the READDIR() function in php?

scandir(directory, order, context)
directoryRequired. Specifies the directory to be scanned
orderOptional. Specifies the sorting order. Default sort order is alphabetical in ascending order (0). Set to SCANDIR_SORT_DESCENDING or 1 to sort in alphabetical descending order, or SCANDIR_SORT_NONE to return the result unsorted 
contextOptional. Specifies the context of the directory handle. Context is a set of options that can modify the behavior of a stream
PHP readdir() method

examples of the READDIR() function

Example 1. In this example, we list files and directories inside the images directory.

$dir = "/images/";

// Sort in ascending order - this is default
$a = scandir($dir);

// Sort in descending order
$b = scandir($dir,1);

PHP rewinddir() Function
PHP readdir() Function
en English
Scroll to Top