gpt4 book ai didi

PHP/MYSQL 图片上传到链接到mysql的服务器

转载 作者:行者123 更新时间:2023-11-29 23:33:36 26 4
gpt4 key购买 nike

我想将新闻系统写入我的网站,我将图像上传到服务器上的文件夹,并将该图像的链接添加到 mysql。最后在现场显示文字和图像。我知道如何在服务器上上传文件,但稍后要做什么...我不知道。有人可以帮我弄这个吗?我不需要现成的脚本,只需要一些如何做的提示。

最佳答案

在上传脚本中,您应该在数据库中添加插入内容,例如 upload.php :

// script upload :
// ....
// ....
// ....
$description = "your text for image";
//$image_name : name extracted from path image.

// script insert :
$stmt = $dbh->prepare ("INSERT INTO table_name (description, image) VALUES (:description, :image)");
$stmt -> bindParam(':description', 'John');
$stmt -> bindParam(':image', $image_name);
$stmt -> execute();

查看结果,例如在 list.php 中:

//========================================
$query = "SELECT * FROM table_name";
$stmt = $dbh->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll();

// Print results :
foreach ($rows as $row) {
echo $row["description"] . "<br/>";
echo "<img src='path/to/img".$row['image']."'/>"
}

关于PHP/MYSQL 图片上传到链接到mysql的服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26463931/

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