Join David Powers for an in-depth discussion in this video Changing the class's defaults, part of Uploading Files Securely with PHP.
- View Offline
…The public methods of the upload file class have…been designed to make it simple to change most defaults.…But you might want to change some of them permanently, also the list of permitted…Mime types and of potentially risky file name…extensions, have been hardcoded into the class definition.…To make changes, open uploadfile.php.…And most of the defaults can be changed in the property…declarations at the top of the class definition.…First one that you might want to change is this one here, maxSize.…
This sets the maximum limit for individual files that can be uploaded.…It's expressed in bytes, and is currently set to 50 kilobytes.…It's important to note that the value of max size must be an integer.…You can't use calculation.…So for example,…if you want to change this to 150 kilobytes, and you try to do this,…150 times 1024, you'll see that I…get a little underline here, and a message here saying that I've got a syntax error.…
You can't have a calculation, it must be a fixed value.…So if you want it to be 150 kilobytes, you would need to put in the correct value,…
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