我的网站有上传配置文件的图像部分,我已经使用了下面的代码。绕过形式输入字段上传不需要的文件
表单代码
<form action="send.php" method="post" enctype="multipart/form-data" name="send" id="send">
Your Image : <input type="file" name="pic" id="pic"/>
<input type="Submit" name="Submit" value="Submit"/>
</form>
PHP代码send.php
$ImageName = $_FILES[pic][name];
if(!empty($ImageName) && $_FILES[pic][type] == "image/jpeg" || $_FILES[pic][type] == "image/png" || $_FILES[pic][type] == "image/gif" || $_FILES[pic][type] == "image/bmp"){
$t = time();
$NewImageName = "$t$ImageName"; // image new name
copy($_FILES[pic][tmp_name], "users/$NewImageName"); // copy it to directory
} else {
echo "no upload done";
}
但是,通过使用Firefox扩展有人设法绕过它,并上载PHP文件 上传者发送文件到我的网站我的消息说:“你只检查类型!” 并表示“我使用了可以伪造输入字段并通过PHP文件的firefox扩展”。
所以我的问题我该如何保护我的图片上传形式的上述代码? 〜感谢
你可以做保护文件夹,即使用户上传php文件,那么PHP文件将不会在该上传文件夹中执行。 –
也许你需要这样的东西:https://github.com/qeremy/image –