@xwero—work with me here. His goal was to provide an operating system compliant string that he could use for the file name. My goal is to accomplish that with no code <grin>.
...so permanently storing the files there would be a bad idea.
You’re going to store it someplace. Realistically your application ‘MAY’ require you to move it. OK, move it if you want. Here’s the point. If you use the name that PHP has already provided, then there is no reason to go through the string manipulation…
If you store files without an extension it’s going to be hard to separate different filetypes if needed.
This is the precise reason for maintaining the cross reference I referred to earlier. This is a common practice. Store the user supplied “file name” complete “with the extension” along with the randomized file name automatically generated by PHP. Store this in your favorite storage mechanism (ini file, XML, DB, etc.). If you need to know the extension, simply look it up!
I think your solutions are not going to stand the test of time.
On the contrary my friend. These are in play everywhere and have been before you and I were hacking code. (Maybe even mean before you were born?). I think sometimes we just think we have to “write a new class and override the world” to echo “Hello World!” these days.
—-
PHP does SO much for us in its core (and it does it so blazingly fast being written in C and all). We should just let it do as much as it can for us. The problem arises when we don’t know about all it’s capabilities. Like CI…I just learned CI has a method csv_from_result() in the DB_util class. I didn’t have a clue. I suppose that might be useful someday.