且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在MySQL中存储一系列图像的***方法是什么?

更新时间:2023-11-28 14:35:34

将图像存储在文件系统上并将路径存储在数据库中..

Store images on your file system and store paths in database..

如果个人资料包含多个图片,则为图片创建一个单独的表格。

If profile has more than 1 images then create a separate table for images.

个人资料表:

id | name | etc | etc
---------------------
1  | abc  | etc | etc
2  | xyz  | etc | etc

图表:

id | profile_id |     image_url     | image_type
-------------------------------------------------
 1 |     1      | images/image1.jpg | screenshot
 2 |     1      | images/image2.jpg | other
 3 |     2      | images/image3.jpg | screenshot 

现在,您可以创建不同的函数来获取特定配置文件的图像。例如:

Now you can create different functions to get images for specific profile. For example:

getProfileImages( profile_id, image_type=NULL ) {
  // run query by joining profiles and images tables.
  // return images paths
}