douhoujun9304
douhoujun9304
2015-06-30 12:02

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

已采纳

I have a simple upload form to upload multiple images

<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>

In my action file I check if the required fields are empty

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

The values are catched via 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"]));

When I upload a small number of images (like 5) it works very well. But when I try to upload a larger number of images (like 20) the data like title, text etc. gets lost and the error to fill in all fields is printed.

How can I prevent this behaviour or is there any way to do so?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doupinyan0186 doupinyan0186 6年前

    Your POST may be hitting limits. You could check the following settings in .htaccess

    php_value post_max_size
    php_value max_input_vars
    
    点赞 评论 复制链接分享

为你推荐