<?php
if($_POST){
$imagentipo=$_FILES['imagen']['type'];
$check=array("image/gif","image/jpeg","image/png");
if(in_array($imagentipo,$check)){
$imagen=$_FILES['imagen']['name'];
$temp=$_FILES['imagen']['tmp_name'];
move_uploaded_file($temp,$imagen);
}
}
?>
<html>
<body>
<form action=test.php method=post enctype=multipart/form-data>
<img src="<?php echo $imagen ?>" width=50 height=50><br>
<input type=file name=imagen accept="image/*"><br>
<input type=submit name=lol>
</form>
</body>
</html>
此代码只允许上传 .jpg .gif .png 文件;但是,这可以通过篡改数据绕过。有什么方法可以防止这种情况?