Key Concepts

Review core concepts you need to learn to master this subject

File System

A file system is a structure of files and directories where computers store all of their information. PHP applications use it for purposes such as content storage, configuration, and logging.

File Handling
Lesson 1 of 1
  1. 1
    Files are everywhere! Just about every piece of data on our computer is stored using files. For example, we could have a document saved into a .pdf file, a photo as a .jpeg, or a song as a .mp4. So…
  2. 2
    Depending on what we want to do with a file, the file handling process can vary. However, the first and last steps will always be the same; we will open the file first, and close it when we’re fini…
  3. 3
    Now that we know how to open and close files, let’s take a look at how to read them. To demonstrate how this works, let’s say we have a file called real-cool-file.txt with the following text: Wow…
  4. 4
    Next, let’s take a look at how to write to a file! The process of writing to a file is similar to reading, except we use the fopen function to open a file in write mode: $file = fopen(“hello.txt”,…
  5. 5
    In the previous exercise, we learned that we can write to a file by opening it in write mode (w). When a file is opened in write mode, any existing content is deleted. Sometimes, we’ll prefer this…
  6. 6
    Nice work! We can now read and write files in PHP. However, you might’ve noticed that most operations, including both reading and writing, can take quite a few steps. For example, here’s what it ta…
  7. 7
    Besides reading and writing, PHP includes several functions that can provide valuable information about a file, such as whether a file exists. For the most part, these functions take a single argum…
  8. 8
    Whenever we’re working with the file system, there’s a lot that can go wrong. If a file operation is unsuccessful, PHP attempts to continue running our program as seamlessly as possible, meaning th…
  9. 9
    Congratulations! You now know all about file handling in PHP. Here’s a recap of what you’ve learned: - Use fopen with the correct mode to access a file for reading, writing, or appending. - Close …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo