如何保护用户不上传php脚本?

时间:2013-03-25 04:07:45

标签: php upload

如何保护用户不上传php脚本?

我将以下代码放入(/ uploads /)文件夹的.htaccess。

<Files ^(*.php|*.phps)>
order deny,allow
deny from all
</Files>
<FilesMatch "\.(php|pl|py|jsp|asp|htm|shtml|sh|cgi.+)$">
ForceType text/plain
</FilesMatch>

但我仍然可以上传php文件&amp; php文件仍然可执行。我或代码有什么问题?

1 个答案:

答案 0 :(得分:0)

$allowed_ext = array("png","jpeg","gif");
$file_name = $_FILES['file']['name'];
$file_ext = end(explode(".",$file_name));
if(in_array($file_ext,$allowed_ext)){
//uplod_here;
}
else{
//reject
}