Join David Powers for an in-depth discussion in this video Adapting the class to handle both single and multiple uploads, part of PHP: Uploading Files Securely.
…Now that we know how the file's array is structured with multiple…uploads, we can adapt the upload method of the upload file class.…Here on line 87, uploaded gets a reference to…the current element in the file's super global array.…With a single file upload, the name element contained a single value.…But with multiple uploads, name is an array.…So we need to create a conditional…statement, to check name. If it's an array, we need to…look through the files, otherwise, the existing code can be executed.…
So let's do that. So if then is array, and what we're…checking, is uploaded, and then the name element of uploaded.…So inside this conditional block, we're going to have to loop…through the name element, and then re-assign to a temporary array.…But if it's not an array, we need to have the existing code put into an…else block, so let's just move that across, and then create…our else block, and then the closing curly brace there.…
So inside this" if"…block, we need to create a for each loop to loop through uploaded name.…
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.