2016-01-13 96 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文件的鏈接,並且有問題嗎? –