2011年1月4日 星期二

[PHP] 上傳檔案過濾檔名特殊字元

安全性考量 :

function clean_file_name($filename)
{
$bad = array(
"<!--",
"-->",
"'",
"<",
">",
'"',
'&',
'$',
'=',
';',
'?',
'/',
"%20",
"%22",
"%3c", // <
"%253c", // <
"%3e", // >
"%0e", // >
"%28", // (
"%29", // )
"%2528", // (
"%26", // &
"%24", // $
"%3f", // ?
"%3b", // ;
"%3d" // =
);

$filename = str_replace($bad, '', $filename);

return stripslashes($filename);
}

【下列文章您可能也有興趣】

2 則留言:

匿名 提到...

請問…
這個function是不是少了一個右括號}

千江有水千江月 提到...

啊! 抱歉~ 補上了.