Help!! How to make a "safe" file name using PHP
Posted: Mon Dec 12, 2011 5:49 pm
Hi all,
Can you help me please?
My goal is to upload files to my web server (from my hard drive). I have written the code for this but I want to be able to handle file names with "illegal" characters in them. So basically I want to remove spaces, etc from file names as they get POST'ed to the PHP code that processes the files.
The strategy that I think is best will be to take all the "legal" characters and keep them, and simply leave out any other characters (including spaces). "Legal" characters for my purposes will be alphanumeric (e.g. a-z (upper and lower case & 0-9).
I assume that I can use preg_replace for this or event load the legal characters into an array and create a string from the array. Any advice would be great. Thanks
Can you help me please?
My goal is to upload files to my web server (from my hard drive). I have written the code for this but I want to be able to handle file names with "illegal" characters in them. So basically I want to remove spaces, etc from file names as they get POST'ed to the PHP code that processes the files.
The strategy that I think is best will be to take all the "legal" characters and keep them, and simply leave out any other characters (including spaces). "Legal" characters for my purposes will be alphanumeric (e.g. a-z (upper and lower case & 0-9).
I assume that I can use preg_replace for this or event load the legal characters into an array and create a string from the array. Any advice would be great. Thanks