How to Remove Spaces from File Names for Added Security


show more Removing spaces from file names provides you with in-depth training on Developer. Taught by David Powers as part of the Uploading Files Securely with PHP show less
please wait ...

Removing spaces from file names

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 ...

Removing spaces from file names
Video duration: 5m 21s 2h 50m Intermediate

Viewers:

Removing spaces from file names provides you with in-depth training on Developer. Taught by David Powers as part of the Uploading Files Securely with PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...