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 - PHP Tutorial
From the course: PHP Techniques: Working with Files and Directories
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
-
-
-
(Locked)
Filesystem basics6m 6s
-
Relative paths and magic constants4m 53s
-
(Locked)
Accessing files5m 4s
-
(Locked)
Reading from files4m 52s
-
(Locked)
Reading line by line5m 9s
-
(Locked)
File permissions5m 34s
-
(Locked)
Writing to files5m 5s
-
(Locked)
Writing line returns2m 28s
-
(Locked)
Deleting files2m 38s
-
(Locked)
Moving the file pointer7m 36s
-
(Locked)
Examining file details6m 52s
-
(Locked)
Challenge: Create a log file2m 2s
-
(Locked)
Solution: Create a log file3m 17s
-
(Locked)
-
-
-