我想创建一个表单,我可以简单地上传图片、pdf 和 doc。因此我创建了以下表格:
<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";
}
当我尝试上传 jpg 或 pdf 时,我总是从脚本末尾收到“错误消息”。我已经尝试了很多东西,但没有解决该错误的方法。
你有想法吗?