我在html中有以下表格:
<form id="signguestbook" class="form-horizontal" action="upload.php" method="post" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="inputName">Uw naam</label>
<div class="controls"><input type="text" id="inputName" placeholder="Uw naam"></div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls"><input type="text" id="inputEmail" placeholder="Email"><span class="maildisclaimer">(uw e-mailadres zal niet op onze site verschijnen)</span></div>
</div>
<div class="control-group">
<label class="control-label" for="inputText">Uw ervaring:</label>
<div class="controls"><textarea rows="5" cols="50" id="inputText" placeholder="Geef hier mee hoe u uw verblijf ervaren heeft!"></textarea></div>
</div>
<div class="control-group">
<label class="control-label" for="inputPhoto">Foto:</label>
<div class="controls"><input type="file" name="photo" id="photo" /></div>
</div>
<div class="control-group">
<div class="controls"><input type="submit" class="btn" value="Versturen" /></div>
</div>
</form>
使用 twitter bootstrap 的布局看起来不错。
然后我有一个带有以下测试代码的upload.php:
<?php
if ($_POST["inputName"]) {
echo "Naam: " . $_POST["inputName"] . "<br />";
}
if ($_POST["inputEmail"]) {
echo "Mail: " . $_POST["inputEmail"] . "<br />";
}
if ($_POST["inputText"]) {
echo "Text: " . $_POST["inputText"] . "<br />";
}
// photo is the name of our file input field
if ($_FILES['photo']['error'] > 0) {
echo "Error: " . $_FILES['photo']['error'] . "<br />";
} else {
echo "File name: " . $_FILES['photo']['name'] . "<br />";
echo "File type: " . $_FILES['photo']['type'] . "<br />";
echo "File size: " . ($_FILES['photo']['size'] / 1024) . " Kb<br />";
echo "Temp path: " . $_FILES['photo']['tmp_name'];
}
?>
我没想到这里有任何错误,但我得到以下信息:
Notice: Undefined index: inputName in /var/www/greze/upload.php on line 3
Notice: Undefined index: inputEmail in /var/www/greze/upload.php on line 6
Notice: Undefined index: inputText in /var/www/greze/upload.php on line 9
File name: 3479331713.pdf
File type: application/pdf
File size: 230.8388671875 Kb
Temp path: /tmp/phpJ4z0FV
我的文件被识别,但没有 $_POST 变量。当我做 var_dump($_POST) 它是一个空数组。所以它应该是我的表单中的东西,但我已经将它设置为 post 并且 enctype 是正确的(我记得)....
我必须承认我的编码已经关闭并且已经有一段时间了。
提前致谢!!