store multiple sizes of one image, filesystem or database approach
<p>I know this question has been ask many times, but mine is more about storing an image that has multiple sizes.</p>

<p>I've already decided that my images will be store in the file system. So, that's checked!</p>

<p>Every master image uploaded via input type="file" will be given an unique id using the unid function in php: uniqid('fc_', true)</p>

<p>Now, my dilemma is how to store the different sizes (or children) of the master image.</p>

<p>As per now, the master image contains a record in the database (id, title, description, type, filename) and it is store in the file system. The different sizes of the master image are move to the file system directly (no record in the database) and they named using the uniqid of the master image + some added text. So:</p>

<pre><code>Master:  fc_345679849.89675849.jpg  
size (30px) : fc_345679849.89675849_tiny.jpg  
size (50px) : fc_345679849.89675849_small.jpg  
size (100px) : fc_345679849.89675849_medium.jpg  
size (500px) : fc_345679849.89675849_large.jpg
</code></pre>

<p>When I started to look more into this system and how others do it, I became more doubtful if it was the correct approach.</p>

<p>The other approach I was thinking of, was the one that stores every image (a reference to the image, not the actual image), including the ones with different sizes in the database. They all will have a primary key and, if it applies, a reference to the master image, like so:</p>

<pre><code>id, ..., filename, master_imageid  
_____________________________
1, ... , 34.jpg, NULL  
2, ... , 23.jpg, 1  
3, ... , 45.jpg, 1  
4, ... , 12.jpg, 1  
5, ... , 8.jpg, 1
</code></pre>

<p>So image <strong>1</strong> is the master, and the rest (different sizes) are children of the master... that is image 2, 3, 4, 5</p>

<p>So, system#1: one record for the master, the children have no db record and have a convenient text to there respective filename to link them to the master.</p>

<p>System#2: one record for the master, and one record for each children. No need to add a convenient text to the filename of the children, coz the column master_imageid will automatically link them to the master.</p>

<p>Any thought on what is the best solution?</p>

<p>Thanks in advance</p>
