2016-01-13 95 views
2

我在尝试获取此上传脚本时遇到问题。它不会上传.swf,即使脚本本身应该可以工作,但我使用了一个用于图像上传器的脚本并对其进行了编辑,因此它应该可以与.swf文件一起使用,但似乎PHP中存在一个问题,它不允许这些类型的文件需要上传。PHP上传脚本不会上传Flash文件。为什么?

任何人都可以帮助我吗?

这是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."; 
     } 
     } 
    } 

?> 
+0

你会得到什么错误? – Ben

+0

对不起,你的文件没有上传。 – Dennis1679

+0

*只有.swf是.... *错误意味着脚本没有正确读取文件名。如果你做'var_dump($ _ FILES [“gameToUpload”])',你看到了什么? – Ben

回答

1

你好你的脚本工作,我这个file尝试和工作正常。但是,当我将文件扩展名更改为SWF时,出现此错误:“对不起,此页仅允许使用.swf对不起,您的文件未上传”。你还必须检查你的文件夹的权限,当然,上传文件夹必须在你的PHP文件的同一级别。

+0

哇,好像你的文件是实际上是我尝试过的唯一实际工作!我想知道为什么这是可能的? – Dennis1679

+0

你能帮我弄清楚为什么一些swf文件会上传,有些不会?我已经将php.ini编辑为'post_max_size = 8M'和'upload_max_filesize = 20M' – Dennis1679

+0

你可以发布你想上传的swf文件的链接,并且有问题吗? –