Join David Powers for an in-depth discussion in this video Moving the file to its destination, part of PHP: Uploading Files Securely.
…If you've created a folder to save the uploaded files, you're now…ready to add the script to move them to their final destination.…Let's begin by creating a variable to store the path to the destination folder.…It needs to go inside this conditional statement…that runs when the form has been submitted.…So let's add a variable called destination.…And the value needs to be a fully qualified…path, not a relative one. I'm going to be uploading files to this…uploaded folder, which is at the same level as form.php in my testing site.…
So what I can do is, I can use a PHP constant to get the…full path to the current folder, and then…add the relative path to the uploaded folder.…The constant I'm going to use is __DIR__ and…the concatenation operator and…DIR doesn't give you a trailing slash. So we need to begin with a forward slash.…Then the name of the folder is uploaded, and a trailing slash at the end.…
That will work for my testing setup.…But if your upload folder is in…a different place, destination will need to match.…
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.