gpt4 book ai didi

php - 通知: Undefined index 'upload'

转载 作者:行者123 更新时间:2023-11-29 13:39:07 26 4
gpt4 key购买 nike

我有一个应用程序,人们可以在其中发布错误。他们可以添加屏幕截图,唯一的是,所有内容都写入我的数据库中,但图像不会保存,我只能看到图像的编号。在 map “上传”中没有保存图像。

这是错误:

Notice: Undefined index: upload in /Applications/MAMP/htdocs/2IMD_KellyVerhaegen_Project2013/loggedIn.php on line 29
Notice: Undefined index: upload in /Applications/MAMP/htdocs/2IMD_KellyVerhaegen_Project2013/loggedIn.php on line 30
Notice: Undefined index: upload in /Applications/MAMP/htdocs/2IMD_KellyVerhaegen_Project2013/loggedIn.php on line 32

PHP 代码:

if (isset($_POST['btnBug'])) 
{
// wanneer er op de knop geklikt is proberen we user te saven in de databank
if (!empty($_POST['btnBug']))
{
/* controleren of titel en beschrijving velden zijn ingevuld */
if(!empty($_POST['subject']) && !empty($_POST['post']))
{
/* zien of de bug kan gesaved worden */
try
{
//nieuwe bug aanmaken en gegevens wegschrijven
$bug = new Bug();
$screenshot = time() . $_FILES['upload']['name'];
move_uploaded_file($_FILES['upload']['tmp_name'],
"uploads/" . $screenshot);
$bug->Bug_Name = $_FILES['upload']['name'];
$bug->Screenshot = $screenshot;
$bug->Post = htmlspecialchars($_POST['post']);
$bug->Subject = htmlspecialchars($_POST['subject']);
//kijken of de bug solved/unsolved is
$keuze = $_POST['myradio'];
if ($keuze == "Unsolved") {
$bug -> Status = "Unsolved";
} else {
$bug -> Status = "Solved";
}
$bug -> User_id = htmlspecialchars($_POST['getUser']);
$bug -> Project_id = htmlspecialchars($_POST['getProject']);
// bug wordt gesaved
$bug->saveBug();
}
catch(Exception $e)
{
$feedback = $e->getMessage();
echo "Vul alle velden in!";
}
}
}
}

我的表格:

<div id="bugform">
<div class="control-group">
<h4>Vul hier u bug in.</h4>
<br />
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" class="form-horizontal">
<label class="control-label" for="inputOnderwerp">Onderwerp</label>
<div class="controls">
<input type="text" name="subject" />
</div>
<br />
<label class="control-label" for="inputBeschrijving">Beschrijving</label>
<div class="controls">
<textarea name="post" name="post"></textarea>
</div>
<br />
<label class="control-label" for="inputUnsolved">Unsolved</label>
<div class="controls">
<input type="radio" name="myradio" value="Unsolved" id="Unsolved" checked="true">
</div>
<br />
<label class="control-label" for="inputSolved">Solved</label>
<div class="controls">
<input type="radio" name="myradio" value="Solved" id="Solved">
</div>
<?php
if(isset($_POST['btnBug']))
{
echo "<img src='uploads/".$screenshot."'/>";

}
?>
<input type="file" name="upload" id="upload" />
<br />
<br />
<br />
<!-- projects ophalen -->
<label class="control-label" for="inputProjectKiezen">Project kiezen</label>
<div class="controls">
<?php
if(mysqli_num_rows($allProjects) > 0)
{
echo "<select name= getProject>";
while ($row = mysqli_fetch_assoc($allProjects))
{
echo "<option value=" . $row['project_id'] . ">" . $row['project_name'] . "</option>";
}
echo "</select>";
}
?>
</div>
<br />
<!-- users ophalen -->
<label class="control-label" for="inputUserToekennen">Aan welke user toekennen?</label>
<div class="controls">
<?php
if(mysqli_num_rows($showUser) > 0)
{
echo "<select name= getUser>";
while ($row = mysqli_fetch_assoc($showUser))
{
echo "<option value=" . $row['user_id'] . ">" . $row['username'] . "</option>";
}
echo "</select>";
}
?>
</div>
<br />
<div class="controls">
<input class="btn btn-info dropdown-toggle" type="submit" name="btnBug" id="btnBug" value="Verzenden" />
</div>
</form>
</div>

我找了一整天了,有人可以帮帮我吗?谢谢。

最佳答案

您需要添加enctype="multipart/form-data"属性为<form>元素。

这样做的原因是默认的 enctype (这就是数据的编码方式)是 application/x-www-form-urlencoded ,它不允许对整个文件进行编码。

关于php - 通知: Undefined index 'upload' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18344465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com