How to organize files created dynamically using php?

I have a PHP site that creates and stores HTML template files on a server based on user input. One user can create many templates. So, to store the template files and associate them with the database record, what I do is

"templates" is a table that contains other information about the template, for example, who created them, etc. with a unique auto increment identifier like template_id

for example - if the template identifier is 1001 I convert it to hex, which is 03e9 Now I split the hexadecimal number into 03 and e9 (after two numbers) becomes a folder and e9 becomes a file with some extension like "e9.tpl"

Here's how I can find a template from the file system if I know the template ID. I do not need to store the file path separately.

Is this a good approach? any flaws in this approach? is there any other approach better than this?

What are the advantages / disadvantages of storing the file path in the database itself? for example, to enable the use of various drives serving templates, etc.?

+3
source share
4 answers

Are you doing this because you are worried that the directory may not contain / inodes? In ext3, the practical limit is about 100,000 files (and 32,000 dirs).

" " , modulu $dir = $id % 1000, ($dir/$id.tpl). 1000 , 100.000.000 .

.

+2

DB UNIQUE, ? 1001.tpl, . , , (, , UNIQUE), 124/1001.tpl.

, .

+4

, , . . .

65 536, 0x10000. , . 0x1234 : 1/1234.tpl, . , .

, , hex. , , . , , , , , , .

:

$path = ($id % NUMBER_OF_FOLDERS) . "/$id.tpl"

$id - .

+1
source

I don’t understand the point of splitting the hex code into two parts to create different folders ... This can create hundreds and hundreds of different folders, which will become a complete mess on your server. Why not just store the templates in the same folder with a hexadecimal value as the file name, for example 03e9.tpl?

0
source

Source: https://habr.com/ru/post/1735007/


All Articles