Creating the class constructor

…We've created a file for the class definition, but so…far, it contains only the namespace and the class declaration.…The definition itself will go between the empty braces.…As explained earlier, a class is basically a collection of functions and…variables, all wrapped up together so they work as a single unit.…Let's begin by creating the class's constructor method.…And on line six between the braces, type the word, public.…And this will indicate that what follows can be used in any PHP script that…includes the class definition. Next, the function keyword, and then…two underscores, and the word, construct, followed by a pair of parentheses.…

This is a fixed name that's used as the constructor method for all classes in PHP.…And in this case, it'll create an UploadFile object to…handle file uploads.…And the method's definition, like an…ordinary function, goes between some curly braces.…An underlying principle of classes and objects is that code should…be generic, so that it can be reused in multiple projects.…

Resume Transcript Auto-Scroll

Author

Released

2/24/2014

The basic process of uploading files with PHP is very simple, but there are security implications that many people are unaware of. This course shows how to create a secure custom PHP class that can handle both single-file and multi-file uploads. Author David Powers shows you how to create a file upload class that checks the size, type, and names of files, renaming them when it encounters a duplicate file name. He'll show you how to make the class report on the outcome of the upload process and the nature of any errors that occur, and how to prevent the user from uploading files that exceed the server limits.

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.