Join David Powers for an in-depth discussion in this video Displaying errors and other messages, part of PHP: Uploading Files Securely.
…We've created an array called messages to report the outcome of the upload.…It's a property of the UploadFile class and if…we go up to the property definition at the top…we can see that it's protected which means that…it can't be accessed from outside of the class definition.…So we'll need to create a public method to return its…contents and inform the user of the outcome of the upload.…It's a good idea to keep public methods together,…so we'll insert the code immediately after the upload method.…
So let's just scroll down a bit and we'll create some extra space here.…Then it will be public, function. And then we'll call it getMessages.…And the definition is very simple, we simply return the messages property.…So it's return…this messages.…Now we've got a way of returning the messages array,…we can improve the move file method at the bottom.…At the moment, we're just using echo.…We can now add this to the messages array, so delete echo and this messages.…
And it needs to be a pair of square brackets at the…
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.