我无法弄清楚为什么我的上传脚本无法上传.SWF,但会上传.JPG .GIF等。
PHP.ini中是否有一些阻止将Flash文件上传到文件夹的设置?
如果有人能帮助我,我会非常开心。
这是脚本。
<?php
include('init.php');
$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}')";
//check if file exists
if (isset($_POST['submit'])) {
$check = $_FILES["gameToUpload"]["tmp_name"];
if (file_exists($target_file)) {
echo "This game is already in the folder.";
$uploadOk = 0;
}
if ($gameFileType != "swf") {
echo "Sorry, only .swf is allowed for this page.";
}
if ($uploadOk = 0) {
echo "Sorry, your file wasn't uploaded.";
}
else {
if (move_uploaded_file($_FILES["gameToUpload"]["tmp_name"], $target_file)) {
echo "The file " . basename($_FILES["gameToUpload"]["name"]). " has been uploaded.";
//$conn->query($query);
}
else {
echo "Sorry, there was an error uploading the file.";
}
}
}
?>
HTML
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select game (*.swf) to upload and add to master.php:
<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>
答案 0 :(得分:0)
您可能希望在upload_max_filesize
上传大于post_max_size
和php.ini
的文件。
答案 1 :(得分:0)
中的php代码有误
if ($uploadOk = 0) {
echo "Sorry, your file wasn't uploaded.";
}
将$uploadOk = 0
更改为$uploadOk != 0
或$uploadOk == 0