我正在尝试上传视频文件,并希望将其保存在名为upload的文件夹中。上传是网站的根目录,我有img css js等。
代码有什么问题,谢谢?
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if ((($_FILES["upload"]["type"] == "video/mp4")
|| ($_FILES["upload"]["type"] == "audio/mp3")
|| ($_FILES["upload"]["type"] == "audio/wma")
|| ($_FILES["upload"]["type"] == "image/pjpeg")
|| ($_FILES["upload"]["type"] == "image/gif")
|| ($_FILES["upload"]["type"] == "image/jpeg"))
&& ($_FILES["upload"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["upload"]["error"] > 0)
{
echo "Return Code: " . $_FILES["upload"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["upload"]["name"] . "<br />";
echo "Type: " . $_FILES["upload"]["type"] . "<br />";
echo "Size: " . ($_FILES["upload"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["upload"]["tmp_name"] . "<br />";
if (file_exists("upload" . $_FILES["upload"]["name"]))
{
echo $_FILES["upload"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["upload"]["tmp_name"],
"/upload" . $_FILES["upload"]["name"]);
echo "Stored in: " . "/upload" . $_FILES["upload"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
</body>
<!DOCTYPE html>
<head>
<title>File Uplaod</title>
</head>
<body>
<form action="Upload.php" method="post" enctype="multipart/form-data">
<label for="file"><span>Filename:</span></label>
<input type="file" name="upload" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>