几个小时以来,我一直在尝试解决这个错误。谁能帮助我错误在哪里?谢谢。我试图将图像上传到 mysql 数据库中。php错误日志直接告诉我错误:未定义索引上传文件。谢谢!
测试.php
Flavor: <input id="flavor" type="text" name="flavor">
Upload image: <input type="file" name="uploadedfile" id="uploadedfile" />
这是我的代码:
<?php
include_once "mysqli.connect.php";
if(isset($_POST['Add']))
{
$flavor = $_POST['flavor'];
$target_path = "images/";
$image = basename($_FILES['uploadedfile']['name']);
$target_path = $target_path . $image;
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
$sql = "INSERT INTO flavor (flavorname, image) VALUES('$flavor','$target_path')";
$result = $mysqli->query($sql);
echo"<script type='text/javascript'>alert('Flavor added!')</script>";
}
else
{
echo"<script type='text/javascript'>alert('Error! Can't proceed.' )</script>";
}
}
?>