Join David Powers for an in-depth discussion in this video Setting and checking the maximum file size, part of PHP: Uploading Files Securely.
…The upload file class is now capable of checking the…error code and displaying messages generated by an upload operation.…The next check should be the size of the uploaded file.…The approach we'll take is to set a default maximum in the…class definition, but offer the option to change it using a public method.…So let's begin by creating a class…property to store the default maximum size.…We'll put it with the…properties up here at the top, and we will make…it a protective property and we'll call it max sign is.…
And we need to assign it a value, and…the value of a class property needs to be fixed.…Unlike the definition of maxinform.php we can't use a calculation.…So to set the value to 50 kilobytes, we'll need to rip out a calculator multiply 50…by 1024 and express the value in bytes, which is 512000.…So that 50 kilobytes is going to be our default, but to make the class…more flexible we need to create a public method to change the value of max size.…
Although using the method will be optional, it'll need to be called before…
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.