Simple way to clean up filenames in PHP
If you want to make sure no silly characters are part of filenames, then you’ll want to sanitize any filenames of files you store on your server. This will make things a whole lot easier in the long run. Certain functions like file_exists(), will return false if the filename contains a %20 instead of a space, even if the file does exist and you can pull it up in your browser. Sanitation will also help if you port your system to a different operating system if you ever move.
You can expand this, but this will remove everything except numbers, letters and (.) periods.