我有一个上传图片的按钮,每次上传图片时,图片都不会保存在数据库中,也不会出现错误,
这是我的代码:
<td>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" required>
<button type="submit" name="files" class="btn btn-primary btn-xs">
Submit
</button>
<?php
if(isset($_POST['files']))
{
$userid = $row['stall_id'];
$a = $_FILES['file']['name'];
$ab = $_FILES['file']['tmp_name'];
$location = "".$a;
move_uploaded_file($ab, "../pictures/".$location);
$sql2 = $conn->prepare("UPDATE stall SET file = ? WHERE stall_id = ?");
$sql2->execute(array($location,$userid));
if($sql){
echo '
<script>
window.location = "stalls.php"
</script>';
}
}
?>
</td>
最佳答案
我自己想出来了,
<td>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" required>
<input type="hidden" name="stall_id" value="<?php echo $value['stall_id']?>">
<button type="submit" name="files" class="btn btn-primary btn-xs">
Submit
</button>
<?php
if(isset($_POST['files']))
{
$userid = $_POST['stall_id'];
$a = $_FILES['file']['name'];
$ab = $_FILES['file']['tmp_name'];
$location = "".$a;
move_uploaded_file($ab, "../pictures/".$location);
$sql2 = $conn->prepare("UPDATE stall SET file = ? WHERE stall_id = ?");
$sql2->execute(array($location,$userid));
if($sql2){
echo '
<script>
window.location = "stalls.php"
</script>';
}
}
?>
</td>
关于php - 上载的图像未保存在数据库中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41455487/