Join David Powers for an in-depth discussion in this video Removing spaces from file names, part of PHP: Uploading Files Securely.
…The remaining stages in making the upload file class more…robust involve inspecting the file name and altering it if necessary.…We'll begin by implementing a simple routine…to replace spaces in file names with underscores.…Spaces are acceptable on Windows and Mac operating systems,…but they cause problems on Linux and in URLs.…So, we'll begin by creating a property to store…the filename if it's been altered.…And, like all properties, it needs to be…declared at the top of the class definition.…
It'll be protected and we'll call it newName.…Now we need to create a protected method, called checkName.…It needs to go with our other check…methods, so we'll put it after the checkType method.…So create a little bit of extra space there…And the argument that we will pass the checkName will be the…reference to the current element in the file's super global array, so…that will be file, and then inside our definition, the first thing…we need to do is to make sure that newName is null.…
The reason for doing that is that the class…
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.