2015-06-30 54 views
2

我有一個簡單的上傳表單來上傳多張圖片HTML圖片上傳導致其他形式的數據

<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(); 
} 

的值通過郵政捕捉

$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)時,標題,文本等數據將丟失,並且打印填寫所有字段的錯誤。

我該如何防止這種行爲,或者有什麼辦法可以這樣做?

回答

1

您的POST可能正在達到極限。 你可以在.htaccess檢查以下設置

php_value post_max_size 
php_value max_input_vars 
+0

max_input_vars設置爲1000 - 所以應該沒有問題 的post_max_size設置爲8M - 我覺得有問題(20張圖片500KB和文字是大比8M) 我有可能增加這些8M嗎? – Phil

+0

是的,嘗試將其設置爲20M,看看它是怎麼回事 –

+0

有關post_max_size的更多信息http://stackoverflow.com/questions/18441083/too-big-post-data-reduce-the-data-or-increase-the- post-max-size –