Join David Powers for an in-depth discussion in this video Setting up to use the class, part of Uploading Files Securely with PHP.
- View Offline
…If you worked through the earlier chapters of this course, you…should be familiar with how to use the upload file class.…This movie and the next one, are mainly for the benefits of those…who've skipped straight to this chapter, or if you need to refresh your memory.…To use the class, you need a web page with a form that contains a file input field.…In my editing program, I've got open form.php and you can find a copy of…this file in the exercise files for this movie.…Let's take a quick look at what this file contains.…
Above the doctype is a small PHP block, on line 2 max is set to 50 times 1024.…1,024 is the number of bytes in a kilobyte.…So this'll be used to set the maximum size of an upload file to 50 kb.…Obviously if you want it to be a different value say 100 or 150, all you…need to do is to change the 50 and PHP will do the calculation for you.…Line 3 result is an empty array.…
This will be used to store the results of the upload.…And those results will be displayed by the PHP block…on lines 14 through to 20 as an unordered list.…
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