...

/

Form Validation for File Uploads

Form Validation for File Uploads

Let's learn how to validate file uploads.

Checking if the user has uploaded a picture

So far, providing a picture was optional. What if we want to force the user to upload a picture? We will have to cover two scenarios:

  1. When the user is creating a new tour, we should verify that the user has uploaded a picture.
  2. When the user is editing a tour, we should verify that the user has uploaded a picture before or that they are uploading a picture now.

Instead of implementing a similar check in two different files, let’s make this part of the validation function we already have in tour-crud.php. If ...

Access this course and 1400+ top-rated courses and projects.