HTML 图片上传导致其他表单数据丢失

HTML image upload results in loss of other form data

我有一个简单的上传表单可以上传多张图片

<form enctype="multipart/form-data" method="post" action="news/insert_news.php" class="form_news" id="newsform">
    <input type="text" class="inputHeading" name="heading" id="heading" maxlength="1000" placeholder="Überschrift" /><br /><br />
    <textarea rows="15" name="text" id="text" maxlength="10000" placeholder="Newstext"></textarea>
    <br /><br />
    <input placeholder="Datum (KLICK)" name="date" id="datepicker" /><br /><br />
    <input type="text" name="author" id="author" placeholder="Autor" /><br /><br />
    <input id="img" name="img[]" type="file" accept="image/*" multiple="multiple" /><br /><br />
    <button type="submit" id="sub">Absenden</button>
</form>

在我的操作文件中,我检查必填字段是否为空

if($title == "" || $text == "" || $author == "" || $date == "") {
    $_SESSION["formError"] = "<p class='formError'>Please fill in all fields.</p>";
    Header("Location: ../news_add.php");
    exit();
}

这些值是通过 post

捕获的
$title = mysql_real_escape_string(strip_tags($_POST["heading"]));
$text = nl2br(mysql_real_escape_string(strip_tags($_POST["text"], "<a><ul><li>")));
$text = trim($text);
$text = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $text);
$author = mysql_real_escape_string(strip_tags($_POST["author"]));
$date = mysql_real_escape_string(strip_tags($_POST["date"]));

当我上传少量图片(比如 5 张)时效果很好。但是,当我尝试上传更多图片(例如 20 张)时,标题、文本等数据会丢失,并且打印出填写所有字段的错误。

我怎样才能防止这种行为或者有什么办法可以做到这一点?

您的 POST 可能已达到极限。 您可以在 .htaccess

中检查以下设置
php_value post_max_size
php_value max_input_vars