安全上传图像/ swf在PHP中

时间:2013-05-29 12:07:23

标签: php image security upload flash

我有Flash游戏网站。在我的面板中,我已经制作了“上传游戏”页面,您可以插入有关游戏的数据。现在,我必须upload image, and swf file,我该如何做到这一点?

请告诉我应该做的检查(图片和swf)。

如果有任何与php一起使用的反病毒,请告诉我。

谢谢大家。

2 个答案:

答案 0 :(得分:0)

$allowedExts = array("gif", "jpeg", "jpg", "png","swf");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
        || ($_FILES["file"]["type"] == "image/jpeg")
        || ($_FILES["file"]["type"] == "image/jpg")
        || ($_FILES["file"]["type"] == "image/pjpeg")
        || ($_FILES["file"]["type"] == "image/x-png")
        || ($_FILES["file"]["type"] == "image/png")
        || ($_FILES["file"]["type"] == "application/x-shockwave-flash")
        )

        && in_array($extension, $allowedExts)) {
    if ($_FILES["file"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
} else {
    echo "Invalid file";
}

答案 1 :(得分:0)

首先检查文件扩展名,然后使用 PHP FILE INFO 扩展名验证文件类型不要依赖扩展程序检查。