简体   繁体   English

将图像存储在Web服务器上的文件系统上的位置

[英]Where to store images on a filesystem on webserver

Where exactly do I store images on a webserver if not in my MySQL database? 如果不在MySQL数据库中,我应该在哪里将图像存储在Web服务器上? I've been told that storing images as a BLOB in a DB is bad practice. 有人告诉我,将图像作为BLOB存储在数据库中是不好的做法。

Also, how do I store references to these images in a DB? 另外,如何在数据库中存储对这些图像的引用? If I have a food_items table, can the table look like this? 如果我有一个food_items表,该表可以像这样吗?

Food Items 食品

Id | ID | Name | 姓名| Description | 描述 Price | 价格 ImageURL 图片网址

1 | 1 | chicken | 鸡| tasty | 好吃 100 | 100 | www.myurl.com/folderwithimages/image.jpg ?? www.myurl.com/folderwithimages/image.jpg ??

Thanks 谢谢

If this is a web server, I would highly recommend you put the image into S3. 如果这是Web服务器,则强烈建议您将映像放入S3。 Here's some documentation regarding Amazon S3 . 这是有关Amazon S3的一些文档。

Avoiding using the db to store images is a good practice, keeping the images in the db not only slows down your db performance it also increases it size and backups, if you are using cloud service then there is also the costs issue. 避免使用数据库来存储图像是一个好习惯,将图像保留在数据库中不仅会降低数据库性能,还会增加数据库的大小和备份,如果您使用的是云服务,那么还会带来成本问题。

Use S3 or Yahoo for this purpose. 为此使用S3或Yahoo。 The only thing left to do is for your site application to connect both this services(db and the Images service),i used this tool . 剩下要做的唯一事情是为您的网站应用程序连接这两个服务(DB和图片服务),我用这个工具

Store the full path only if each image resides in a diffrent location, it make no sense storing the same data for each data entry, 仅当每个图像位于不同的位置时才存储完整路径,为每个数据条目存储相同的数据是没有意义的,

I would recommend storing only the image name in the database, and keeping all the images in /yoursiteroot/folderwithimages. 我建议仅在数据库中存储图像名称,并将所有图像保留在/ yoursiteroot / folderwithimages中。

That table looks good, but I wouldn't recommend storing the full URL in case you want to change the path or URL of the images in the future. 该表看起来不错,但是我不建议存储完整的URL,以防将来您要更改图像的路径或URL。

Store images in a /images folder in the filesystem on the webserver 将图像存储在Web服务器上文件系统的/ images文件夹中

In your database do not store the full URL to the image. 在您的数据库中,不要存储图像的完整URL。 Store a relative URL to the image so if your domain changes you don't have to update the database again. 将相对URL存储到图像,这样,如果您的域发生更改,则不必再次更新数据库。

/images/image.jpg /images/image.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM