In the snippet below I am trying to remove any special character from an uploaded pictures file name.
EXAMPLE: Mikes & Lisa's Pictures.jpg
In this example I am trying to eliminate the & and single quote. What I wind up with is something like
"Mikes & Lisa" and a sub directory called "s Pictures.jpg"
or
Mikes & Lisa\'s Pictures.jpg
In the various combinations I try to eliminate special characters I am just adding more bad files I cant delete to a directory.
I have another thread going to try and prevent this in Java from getting here in the first place but want to cover all my bases. Other threads I have read on this subject seem incomplete or the concept doesn't seem to work.
Can someone correct or point me in the right direction so that the file copied from the temp upload area has a clean file name when it hits my directory? I marked this as advanced because I haven't seen any code that does this in PHP.
If possible I would like to get rid of the # also which just recently started showing up.
CODE
if (($ext === ".jpg")||($ext === "jpeg")){
$value = htmlspecialchars($value, ENT_QUOTES);
$value = preg_replace('&039;/', '_', $value);
$NewImageName = $t."-".$value;
copy($_FILES[images][tmp_name][$key], "re_images/".$NewImageName);
I Had trouble posting all the code so I changed the Preg_Replace with some misc dataThis post has been edited by Mitchell2038: 9 May, 2008 - 12:17 PM