PHP上传脚本不会上传Flash文件。为什么?

时间:2016-01-13 11:50:59

标签: php flash

我在尝试使用此上传脚本时遇到问题。它没有上传.swf,即使脚本本身应该工作,我使用脚本进行图像上传并编辑它以便它可以使用.swf文件,但似乎PHP中的问题没有&# 39; t允许上传这些类型的文件。

任何人都可以帮我吗?

这是html

    <!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select game (*.swf) to upload and add to the list of games:
    <input type="file" name="gameToUpload" id="gameToUpload">
    <input type="text" name="nameOfGame" id="nameOfGame">
    <input type="submit" value="Upload Game" name="submit">
</form>

</body>
</html> 

这是PHP

<?php

    include('init.php');

    //Reminder to self: Turn off when finished coding!!
    error_reporting(-1);     

    //Some querys and variables used later on
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["gameToUpload"]["name"]);
    $uploadOk = 1;
    $gameFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    $gameName = $_POST["nameOfGame"];
    $query = "INSERT INTO `beoordelingen`.`beoordeling` (`ID`, `file`, `Spel`) VALUES (NULL, '{$target_file}', '{$gameName}')";

    //If submit is pressed
    if (isset($_POST['submit'])) {

        $check = $_FILES["gameToUpload"]["tmp_name"];

        //Check if file already exists in folder
        if (file_exists($target_file)) {
            echo "This game is already in the folder.";
            $uploadOk = 0;
        }
        //Check if the file type is .SWF
    if ($gameFileType != "swf") {
            echo "Sorry, only .swf is allowed for this page.";
            $uploadOk = 0;
        }
        //When any errors occured do not go passed this statement
        if ($uploadOk === 0) {
            echo "Sorry, your file wasn't uploaded.";
        }
    //If no errors have occured then continue with this
    else {
        //Move the file from the temporary folder to the final destination
        if (move_uploaded_file($_FILES["gameToUpload"]["tmp_name"], $target_file)) {
            echo "The file " . basename($_FILES["gameToUpload"]["name"]). " has been uploaded.";
            //Update the mysql database
            $conn->query($query);
        }
        //If something bad happened while trying to move the file. Show this message to the user.
        else {
            echo "Sorry, there was an error uploading the file.";
        }
      }
    }

?>

1 个答案:

答案 0 :(得分:1)

您好我的脚本正在运行我已尝试使用此file并且工作正常。但当我将文件扩展名更改为SWF时,我收到此错误:“抱歉,此页面仅允许.swf。抱歉,您的文件未上传”。您还必须检查文件夹权限,当然,上传文件夹必须与您的php文件处于同一级别。

相关问题