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 files

Accessing files - PHP Tutorial

From the course: PHP Techniques: Working with Files and Directories

Start my 1-month free trial

Accessing files

- [Instructor] Now that we know how to construct file paths, we're ready to learn how to access files. In PHP, you're most often going to do that with the fopen function. Fopen opens a file so that you can work with it. It doesn't matter if you plan on reading from it or writing to it, you first have to open it. The fopen function returns a file handle. This is a reference to the open file that we can then use to read from it, to write to it and to close it when we're done. If fopen fails to open the file, it'll return false. Notice that fopen takes two arguments. The first is the path to the file that we want to open. The second is the file access mode. Let's talk about what the options are for the mode. The mode is a short string, which is an abbreviation for the way that we want to access the file. If we use R, PHP will open the file in read mode. It will allow us to read from the file starting at…

Contents