Join David Powers for an in-depth discussion in this video Checking the error level, part of PHP: Uploading Files Securely.
…In the upload file class definition, the upload…method calls a protected method called check file that…needs to run a series of checks before the…uploaded file can be moved to its final destination.…As you can see here on line 22, the argument path to check file is uploaded.…This contains a reference to the current element in the…file super global array; which allows us to access the name,…error and other details of the uploaded file directly as a simple array.…
The first check we need to make is the error code stored in the files array.…So let's get to work on the check file method.…So we need to insert a line above this line here, and inside the check file…method, uploaded is referred to as file. So we can get the…error code with file error.…So we need a conditional statement here, if file, then error.…If that's not equal to zero, we know there's a problem.…
So what we need to do here, is to call…another protected method which will be called, get error message.…And pass it a reference to file. This, and the arrow operator…
At the end of this course, you'll have a robust, flexible class that can be incorporated into many projects (including web forms) with just a few lines of code.
- How PHP handles file uploads
- Setting the maximum file size
- Moving the file to its destination
- Creating and using a namespaced class
- Displaying error messages
- Restricting unacceptable MIME types and file extensions
- Using the class
- Reporting errors
- Altering the user
Skill Level Intermediate
1. File-Upload Basics
2. Creating a File-Upload Class
Checking the error level5m 7s
3. Making the Class More Secure
4. Handling Multiple File Uploads
5. Using the Class
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.