mardi 30 juin 2015

HTML image upload results in loss of other form data

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?

Aucun commentaire:

Enregistrer un commentaire