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.?
source
share