在MySQL中存储图像/数据和命名约定

时间:2022-01-20 16:46:37

What are some ideas out there for storing images on web servers. Im Interacting with PHP and MySQL for the application.

有什么想法在Web服务器上存储图像。我正在与PHP和MySQL交互应用​​程序。

Question 1

Do we change the name of the physical file to a000000001.jpg and store it in a base directory or keep the user's unmanaged file name, i.e 'Justin Beiber Found dead.jpg'? For example

我们是否将物理文件的名称更改为a000000001.jpg并将其存储在基本目录中或保留用户的非托管文件名,即“Justin Beiber Found dead.jpg”?例如

wwroot/imgdir/a0000001.jpg

and all meta data in a database, such as FileName and ReadableName, Size, Location, etc. I need to make a custom Filemanager and just weighing out some pros and cons of the underlying stucture of how to store the images.

以及数据库中的所有元数据,例如FileName和ReadableName,Size,Location等。我需要制作一个自定义的Filemanager,然后权衡一下如何存储图像的基本结构的优缺点。

Question 2

How would I secure an Image from being downloaded if my app/database has not set it to be published/public?

如果我的应用程序/数据库没有将其设置为发布/公开,我将如何保护图像不被下载?

In my app I can publish images, or secure them from download, if I stored the image in a db table I could store it as a BLOB and using php prevent the user from downloading it. I want to be able to do the same with the image if it was store in the FileSystem, but im not sure if this is possible with PHP and Files in the system.

在我的应用程序中,我可以发布图像,或保护它们免于下载,如果我将图像存储在db表中,我可以将其存储为BLOB并使用php阻止用户下载它。如果它存储在FileSystem中,我希望能够对图像做同样的事情,但我不确定这是否可以在系统中使用PHP和文件。

1 个解决方案

#1


3  

Keeping relevant file names can be good for SEO, but you must also make sure you don't duplicate.

保持相关文件名对SEO有利,但您还必须确保不重复。

In all cases I would rename files to lowercase and replace spaces by underscores (or hyphens)

在所有情况下,我都会将文件重命名为小写,并用下划线(或连字符)替换空格

Justin Beiber Found dead.jpg => justin_beiber_finally_dead.jpg

Justin Beiber发现dead.jpg => justin_beiber_finally_dead.jpg

If the photo's belongs to an article or something specific you can perhaps add the article ID to the image, i.e. 123_justin_beiber_found_dead.jpg. Alternatively you can store the images in an article specific folder, i.e. /images/123/justin_beiber_found_dead.jpg.

如果照片属于某篇文章或特定内容,您可以将文章ID添加到图像中,即123_justin_beiber_found_dead.jpg。或者,您可以将图像存储在文章特定的文件夹中,即/images/123/justin_beiber_found_dead.jpg。

Naming the files like a0000001 removes all relevance to the files and adds no value whatsoever.

将文件命名为a0000001会删除与文件的所有相关性,并且不会添加任何值。

Store (full) filepaths only in the database.

仅在数据库中存储(完整)文件路径。

For part 2;

第2部分;

I'm not sure what the best solution here is, but using the filesystem, I think you will have to configure apache to serve all files in a particular directory by PHP. In PHP you can then check if the file can be published and then spit it out. If not, you can serve a dummy image. This however is not very efficient and will be much heavier on apache.

我不确定这里最好的解决方案是什么,但是使用文件系统,我认为你必须配置apache来为PHP提供特定目录中的所有文件。在PHP中,您可以检查文件是否可以发布,然后将其吐出。如果没有,您可以提供虚拟图像。然而,这不是非常有效,并且在apache上会更加沉重。

#1


3  

Keeping relevant file names can be good for SEO, but you must also make sure you don't duplicate.

保持相关文件名对SEO有利,但您还必须确保不重复。

In all cases I would rename files to lowercase and replace spaces by underscores (or hyphens)

在所有情况下,我都会将文件重命名为小写,并用下划线(或连字符)替换空格

Justin Beiber Found dead.jpg => justin_beiber_finally_dead.jpg

Justin Beiber发现dead.jpg => justin_beiber_finally_dead.jpg

If the photo's belongs to an article or something specific you can perhaps add the article ID to the image, i.e. 123_justin_beiber_found_dead.jpg. Alternatively you can store the images in an article specific folder, i.e. /images/123/justin_beiber_found_dead.jpg.

如果照片属于某篇文章或特定内容,您可以将文章ID添加到图像中,即123_justin_beiber_found_dead.jpg。或者,您可以将图像存储在文章特定的文件夹中,即/images/123/justin_beiber_found_dead.jpg。

Naming the files like a0000001 removes all relevance to the files and adds no value whatsoever.

将文件命名为a0000001会删除与文件的所有相关性,并且不会添加任何值。

Store (full) filepaths only in the database.

仅在数据库中存储(完整)文件路径。

For part 2;

第2部分;

I'm not sure what the best solution here is, but using the filesystem, I think you will have to configure apache to serve all files in a particular directory by PHP. In PHP you can then check if the file can be published and then spit it out. If not, you can serve a dummy image. This however is not very efficient and will be much heavier on apache.

我不确定这里最好的解决方案是什么,但是使用文件系统,我认为你必须配置apache来为PHP提供特定目录中的所有文件。在PHP中,您可以检查文件是否可以发布,然后将其吐出。如果没有,您可以提供虚拟图像。然而,这不是非常有效,并且在apache上会更加沉重。