我的表单过去总是有效,但是当我尝试上传多张图片时,它突然无法识别POST输入。
我尝试过几件事情,包括:查看PHP.INI以查看是否有错误,print_r数组以查看其中的内容(它是空的),制作确定输入字段有一个动作和名称,并删除不相关的javascript,但似乎没有任何效果。我确定我忽略了一些东西,但我已经检查了一切我认为可能是错误的东西。
谢谢我提前!
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ((isset($_POST['title'])) && (isset($_POST['title_small'])) && (isset($_POST['article_small'])) && (isset($_POST['article'])) && (!empty($_POST['title'])) && (!empty($_POST['title_small']))
&& (!empty($_POST['article_small'])) && (!empty($_POST['article'])))
{
include('../includes/database.php');
$title = $_POST['title'];
$title_small = $_POST['title_small'];
$article_small = $_POST['article_small'];
$article = $_POST['article'];
if($_FILES['file_array']['error'][0] == 0)
{
$name_array = $_FILES['file_array']['name'];
$tmp_name_array = $_FILES['file_array']['tmp_name'];
$type_array = $_FILES['file_array']['type'];
$size_array = $_FILES['file_array']['size'];
$error_array = $_FILES['file_array']['error'];
$imgnames = implode(',', $name_array);
for($i = 0; $i < count($tmp_name_array); $i++)
{
// Check if image file is a actual image or fake image
$check = getimagesize($tmp_name_array[$i]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
$target_file = "../uploads/" . $name_array[$i];
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($size_array[$i] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
$extensions = pathinfo($name_array[0], PATHINFO_EXTENSION);
// Allow certain file formats
if($extensions != "jpg" && $extensions != "JPG" && $extensions != "png" && $extensions != "jpeg" //AANPASSEN HOOFDLETTERS
&& $extensions != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
}
else
{
if(move_uploaded_file($tmp_name_array[$i], "../uploads/".$name_array[$i]))
{
echo $name_array[$i]." upload is complete<br>";
}
else
{
echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
}
}
}
$sql = "INSERT INTO articles (title, title_small, article_small, article, image_article) VALUES ('$title', '$title_small', '$article_small', '$article', '$imgnames')";
if (mysqli_query($conn, $sql))
{
header('location: ../paper.php');
}
else
{
echo "error:" . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
}
else
{
array_push($errors, "You forgot something!");
}
}
}
?>
形式:
<form class="form" id="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input name="title" type="text" class="feedback-input" placeholder="Title" maxlength="100"/>
<input name="title_small" type="text" class="feedback-input" placeholder="Small Title" maxlength="100"/>
<textarea name="article_small" class="feedback-input" id="comment" placeholder="Small Article"></textarea>
<textarea name="article" class="feedback-input" id="comment" placeholder="Article"></textarea>
<input type="file" name="file_array[]" accept="image/*" id="imguploadsmall" />
<input type="submit" value="ADD" id="button-blue" name="submit" />
</form>
</div>
编辑:vardump:
array (size=0)
empty
array (size=40)
'HTTP_HOST' => string 'localhost' (length=9)
'HTTP_CONNECTION' => string 'keep-alive' (length=10)
'CONTENT_LENGTH' => string '14140480' (length=8)
'HTTP_CACHE_CONTROL' => string 'max-age=0' (length=9)
'HTTP_ACCEPT' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' (length=74)
'HTTP_ORIGIN' => string 'http://localhost' (length=16)
'HTTP_UPGRADE_INSECURE_REQUESTS' => string '1' (length=1)
'HTTP_USER_AGENT' => string 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36' (length=110)
'CONTENT_TYPE' => string 'multipart/form-data; boundary=----WebKitFormBoundary50iFmEAIoV7IB7mF' (length=68)
'HTTP_REFERER' => string 'http://localhost/ded6/admin/add_article.php' (length=43)
'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate' (length=13)
'HTTP_ACCEPT_LANGUAGE' => string 'nl,en-US;q=0.8,en;q=0.6,de;q=0.4,af;q=0.2,es;q=0.2,fr;q=0.2,zh-TW;q=0.2' (length=71)
'HTTP_COOKIE' => string 'PHPSESSID=2mnctabpk7qd2v76v0k6l9h3q3' (length=36)
'PATH' => string 'C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\In'... (length=1185)
'SystemRoot' => string 'C:\WINDOWS' (length=10)
'COMSPEC' => string 'C:\WINDOWS\system32\cmd.exe' (length=27)
'PATHEXT' => string '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC' (length=53)
'WINDIR' => string 'C:\WINDOWS' (length=10)
'SERVER_SIGNATURE' => string '<address>Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80</address>
' (length=79)
'SERVER_SOFTWARE' => string 'Apache/2.4.9 (Win64) PHP/5.5.12' (length=31)
'SERVER_NAME' => string 'localhost' (length=9)
'SERVER_ADDR' => string '::1' (length=3)
'SERVER_PORT' => string '80' (length=2)
'REMOTE_ADDR' => string '::1' (length=3)
'DOCUMENT_ROOT' => string 'C:/wamp/www/' (length=12)
'REQUEST_SCHEME' => string 'http' (length=4)
'CONTEXT_PREFIX' => string '' (length=0)
'CONTEXT_DOCUMENT_ROOT' => string 'C:/wamp/www/' (length=12)
'SERVER_ADMIN' => string 'admin@example.com' (length=17)
'SCRIPT_FILENAME' => string 'C:/wamp/www/DED6/admin/add_article.php' (length=38)
'REMOTE_PORT' => string '34620' (length=5)
'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
'REQUEST_METHOD' => string 'POST' (length=4)
'QUERY_STRING' => string '' (length=0)
'REQUEST_URI' => string '/ded6/admin/add_article.php' (length=27)
'SCRIPT_NAME' => string '/ded6/admin/add_article.php' (length=27)
'PHP_SELF' => string '/ded6/admin/add_article.php' (length=27)
'REQUEST_TIME_FLOAT' => float 1463656788.598
'REQUEST_TIME' => int 1463656788
只有错误是:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\DED6\admin\add_article.php:2) in C:\wamp\www\DED6\includes\header.php on line 3
答案 0 :(得分:0)
看起来它对php.ini中的文件相关设置有一些限制。尝试上传非常小的文件并检查。 php错误日志提供了详细的错误信息。