0
我想創建一個表單,我只需上傳圖片,pdf和文檔。 因此,我創建了以下形式:無法上傳文件(pdf,jpg等)
<form method="post" action="index.php?op=editpress&save=1" enctype="multipart/form-data">
<label for="file" class="control-label">Neue Datei hochladen:</label>
<input type="file" id="file" name="file">
</form>
的PHP-代碼:
if($_GET['save'] == 1 AND isset($_POST['submit'])) {
$allowedExts = array("pdf","doc","docx","png","jpg","jpeg","gif");
$allowedMimeTypes = array('application/msword','application/pdf','image/gif','image/jpeg','image/jpg','image/png');
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if (in_array($_FILES["file"]["type"], $allowedMimeTypes) AND (5000000 < $_FILES["file"]["size"]) AND (in_array($extension, $allowedExts)))
{
if ($_FILES["file"]["error"] > 0)
{
echo "There was an error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
if (file_exists("../media/presse/" . $_FILES["file"]["name"]))
{
unlink("../media/presse/" . $_FILES["file"]["name"]);
}
move_uploaded_file($_FILES["file"]["tmp_name"],"../media/logo/" . $_FILES["file"]["name"]);
}
}
else
{
echo "Here comes the errormessage";
}
我總是從腳本的末尾獲得「errormessage的」,當我嘗試上傳JPG或PDF格式。 我已經嘗試了很多東西,但沒有發現錯誤的解決方案。
你有什麼想法嗎?
Hi Rob W, 謝謝!我沒有看到...,謝謝你的提示!現在一切正常。 –