Join David Powers for an in-depth discussion in this video Moving the file to its destination, part of PHP: Uploading Files Securely.
…We've created an upload file class that performs a series of…checks on a file that's been uploaded to a web server.…It checks the error code, the size.…It optionally checks the mime type, and it also checks the name.…There's just one thing missing: it doesn't actually move the file to its destination.…Let's fix that right now.…Basically, all we need to do is to add the Move Upload File function…with the Move File Method.…And, the Move File Method is right down at the bottom of our class definition.…
And, so, let's just add in a new line at the top of the definition there.…We first need to find out if the file has been renamed.…So we'll create a variable to store that.…And we know the file is being renamed if there's…a value that's being set in the new name property.…So we can use that is the condition is set, this new name.…Then the conditional operator. If it has been set we'll use that.…If it hasn't been set we'll use the original name…which is stored as file and then the name element.…
The move uploaded file function returns true or false…
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.