For example, you can use PHP to read or write a text file. Or you can list all files in a specified folder. There are many possibilities and PHP can save you lots of tedious work.
Here, we'll look at how you can use PHP to work with folders and files. The goal is to give you a quick overview. In the next lessons, we will look more closely at the different possibilities. We will not go through all the different possibilities. Again, see the documentation for a complete listing.
- filemtime
- Returns the time for which the contents of a file was last edited (as UNIX timestamp - see lesson 4)).
- fileatime
- Returns the time when a file was last accessed / opened (as a UNIX timestamp - see lesson 4)).
- filesize
- Returns the size of a file in bytes.
show example
Folders
PHP also allows you to work with folders on the server. We will not go through all the different possibilities - only show an example. Again, see the documentation for more information.- opendir
- Opens a specified folder.
- readdir
- Returns the filename of the next file in the open folder (cf. opendir)
- closedir
- Closes a specified folder.
show example
In the example the directory "../../tutorials/php/" is first opened. Then a loop is used to write the name of the next file in the folder as long as there are more files. At the end, the folder is closed.
In the next lessons, we will look at how to read from and write to a text file.