Backend Development 2 min read

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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP opendir() Function – Opening a Directory Handle

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: dir
BackendPHPFilesystemdirectoryopendir
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.