Join David Powers for an in-depth discussion in this video Neutralizing potentially dangerous uploads, part of PHP: Uploading Files Securely.
…The allow all types method that we've created on line 71…to 81, makes the upload file class accept all types of files.…It also allows you to specify whether a suffix should…be appended to the file name of potentially risky types.…We now need to amend the check name method so…that it renames files correctly and appends that suffix, if necessary.…So let's find the check name method.…It's down towards the bottom of the class definition.…
There it is.…We need to add an extra line on line 165.…And the first task, is to extract the file name extension.…The file name is stored here in no spaces.…We can get the extension by passing nospaces as…an argument to the built-in PHP function path info,…which returns an associative array of information about a file or a file path.…So we'll create a variable called nameparts…and pathinfo. Nospaces.…
If the file name doesn't have an extension, the extension element of…nameparts won't have been set, so we need to check if it exists.…So let's create a variable to store the extension.…
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.