gpt4 book ai didi

php - 上传的图片不保存在数据库中

转载 作者:行者123 更新时间:2023-11-28 02:46:14 24 4
gpt4 key购买 nike

我有一个上传图片的按钮,每次我上传图片时,图片都不会保存在数据库中,也没有给出错误,

这是我的代码:

<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/

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