我在嘗試獲取此上傳腳本時遇到問題。它不會上傳.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.";
}
}
}
?>
你會得到什麼錯誤? – Ben
對不起,你的文件沒有上傳。 – Dennis1679
*只有.swf是.... *錯誤意味着腳本沒有正確讀取文件名。如果你做'var_dump($ _ FILES [「gameToUpload」])',你看到了什麼? – Ben