PHP opendir() Function – Opening a Directory Handle
This article explains PHP's opendir() function, detailing its purpose of opening a directory handle, the required path and optional context parameters, the return values, and provides a complete code example that reads and displays filenames and their types within a specified directory.
The PHP opendir() function opens a directory handle, returning a resource on success or FALSE on failure.
Parameters
path – the directory path to open.
context – optional context resource.
Return value – a directory handle resource if successful, otherwise FALSE.
Example
Output
filename: . : filetype: dir
filename: .. : filetype: dir
filename: apache : filetype: dir
filename: cgi : filetype: dir
filename: cli : filetype: dirLaravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.