上传图片名称

时间:2013-07-21 21:17:56

标签: php mysql

我正在将图片名称上传到数据库!

问题是名称在数据库中,名称前面有空格!

问题出在哪里?

$original_name = strtolower(trim($arquivo['name']));
$caracteres = array("ç","~","^","]","[","{","}",";",":","´",",",">",
                   "<","-","/","|","@","$","%","ã","â","á","à","é",
                  "è","ó","§","ò","+","=","*","&","(",")","!","#","?",
                  "`","ã"," ","©","£");

$original_name = str_replace(' ', '', $original_name);
$final_name = str_replace($caracteres,"",$original_name);

1 个答案:

答案 0 :(得分:2)

我建议使用允许字符的白名单,例如[a-zA-Z0-9_]

并使用:

$final_name = preg_replace("#[^a-z0-9_]+#i", "", $arquivo['name']);