From the course: PHP Techniques: Working with Files and Directories
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Accessing directory contents - PHP Tutorial
From the course: PHP Techniques: Working with Files and Directories
Accessing directory contents
- [Instructor] In this movie, we'll learn how to list the files and directories which are inside a directory so that we can work with them. We'll be working with three PHP functions, opendir, readdir and closedir. These are very similar to the PHP functions we use to work with files. Opendir works a lot like fopen. It opens up a directory at the given path and returns a directory handle which we can use to reference the directory. Readdir works like fread and it reads information from the directory. Closedir works like fclose and closes the open directory. Let's try them out. Let's start by creating a new file in our PHP sandbox and we'll save it as dir_access.php. And let's copy everything that's inside file_access.php as a starting point because it's going to be very similar. We'll jump over here, we'll paste in and I can close file access now. Now, let's change this from file path to instead be dir path.…
Contents
-
-
-
-
(Locked)
Directory basics4m 4s
-
(Locked)
Creating and deleting directories2m 53s
-
(Locked)
Accessing directory contents6m 18s
-
(Locked)
Skipping directory entries3m 23s
-
Pattern matching with glob5m 13s
-
(Locked)
Challenge: Directory treasure hunt1m 57s
-
(Locked)
Solution: Directory treasure hunt3m 49s
-
(Locked)
-
-