首页 > 解决方案 > 是否可以使用 TextArea 将图像插入数据库并使用 PHP 和 MySQL 在 Web 上显示?

问题描述

是否可以使用 TextArea 将图像插入数据库并使用 PHP 和 MySQL 在 Web 上显示?

如果可能,请告诉我如何做到这一点。

谢谢。

标签: phpmysqlimagetextarea

解决方案


实际上,您不能将图像插入到 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 数据库


推荐阅读