gpt4 book ai didi

php - 使用 PHP 在 MySQL 数据库中存储多个图像

转载 作者:行者123 更新时间:2023-11-30 22:03:29 25 4
gpt4 key购买 nike

我是 PHP 新手。

我正在尝试将带有文本的多个图像添加到数据库中,但我被卡住了。如果我选择一个,它就会被存储。如果我选择多个,它在数据库中将保留为空白。

我需要帮助来解决这个问题。另外,我很困惑:数据库中的一张图片表可以吗?我的意思是,是否有一种特殊的数据类型或方法可以在数据库中的同一条目上放置多个图像?

这是我的代码:

<html>
<body>
<form class="container" enctype ='multipart/form-data' action="add.php" method="post">
<label><b> Name: </b></label><br><br>
<input type="text" name="name"><br><br>
<label><b> Type: </b></label><br><br>
<input type="text" name="type"><br><br>
<label><b> Detail: </b></label><br><br>
<input type="text" name="detail"><br><br>
<label><b> Area: </b></label><br><br>
<input type="text" name="area"><br><br>

Select image to upload:
<input type="file" name="filename" size='10000' multiple>
<input type="submit" value="Upload Image">
</form>
<?php
// error_reporting(E_ALL); ini_set('display_errors', 1);

require_once 'login.php';

$db_server = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);
if (!$db_server) die("unable to connect to mysqli:" . mysqli_error());

mysqli_select_db($db_server, "dbase1") or die("db not selected" . mysqli_error());

$name = $_POST["name"];
$type = $_POST["type"];
$detail = $_POST["detail"];
$area = $_POST["area"];

if($_FILES)
{
$namee = $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $namee);
echo "uploaded image'$namee'<br><img src ='$namee'>";
}

$source= "pictures/".$namee;

$sql = "INSERT INTO adprop (name, type, text,area,filename) VALUES ('$name','$type','$detail','$area','$source')";
$db = $db_server->query($sql);
?>
</body>
<html>

预先感谢您的帮助!

最佳答案

例如,如果你想在一个字段中保存多个图像路径,你可以将它们添加到数据库中,如下所示:

/image_folder/image_name1.jpg,/image_folder/image_name2.jpg

并使用splitfor loop 在用户界面中动态打印它们。

关于php - 使用 PHP 在 MySQL 数据库中存储多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42565733/

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