Image / data storage in MySQL and naming conventions

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

Question 1

We will change the name of the physical file to a000000001.jpg and save it in the base directory or save an unmanaged username, i.e. "Justin Beiber Found dead.jpg"? for example

 wwroot/imgdir/a0000001.jpg 

and all the metadata in the database, such as FileName and ReadableName , Size , Location , etc. I need to create my own Filemanager and just weigh some of the pros and cons of the basic image storage structure.

Question 2

How can I protect an image from downloading if my application / database has not set its publication / publication?

In my application, I can publish images or protect them from loading, if I saved the image in the db table, I could store it as a BLOB and use php so that the user does not upload it. I want to be able to do the same with an image if it was a repository in FileSystem, but I'm not sure if this is possible with PHP and files in the system.

0
source share
1 answer

Keeping the appropriate file names can be useful for SEO, but you should also make sure that you are not duplicating.

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

Justin Beiber Found dead.jpg => justin_beiber_finally_dead.jpg

If the photo belongs to any article or something specific, you can add the article identifier to the image, i.e. 123_justin_beiber_found_dead.jpg . In addition, you can save images in a folder specific to the article, i.e. /images/123/justin_beiber_found_dead.jpg

File naming of the type a0000001 removes all relevance for files and does not add any value.

Store (full) file path only in the database.

For part 2;

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

+3
source

All Articles