php - 是否可以使用 TextArea 将图像插入数据库并使用 PHP 和 MySQL 在 Web 上显示?
问题描述
是否可以使用 TextArea 将图像插入数据库并使用 PHP 和 MySQL 在 Web 上显示?
如果可能,请告诉我如何做到这一点。
谢谢。
解决方案
实际上,您不能将图像插入到 mySQL 数据库中,但您可以使用php readdir function来做到这一点。首先,您可以将文件上传到特定文件夹,然后使用此功能显示它们。为此,您可以使用以下代码:
<?php
$dir = "your_intended_path_here";
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
if ($file != "." and $file != "..") {
echo "<img src='" . $dir . $file . "'>";
}
}
closedir($dh);
}
}
?>
您可以将图像插入 mysql 数据库。这是教程: https ://www.roseindia.net/sql/mysql-example/insert-image.sql.shtml#:~:text=Following%20is%20the%20example%20of,the%20image%20data% 20 到 %20 数据库。
推荐阅读
- amazon-web-services - 从公有弹性集群迁移到 VPC 集群
- javascript - 谷歌翻译小部件延迟显示在网页上
- amazon-s3 - 将名称包含斜杠的文件上传到 AWS S3 存储桶
- sql - 如何插入多个insert sql语句
- kotlin - 如何在 Kotlin Multiplatform 中将默认的 `jvm` sourceSet 添加到 `android` 目标?
- swift - 如何获取已编辑的 NSOutlineView 文本字段单元格的“项目”或行索引?
- python - 避免数据帧 groupby 结果变成系列
- youtube-iframe-api - 如何在 youtube api 嵌入代码中删除更多视频 div
- php - dropzone 传递空文件名
- angular - Angular 将下拉选择选项设置为迭代前的默认选择