Reputation: 6294
I'm developing a website and i'm handling the users uploads like this:
there is a unique key for each user, lets say a user has the key "aaabbbccc". Right now im saving this users uploads to a directory-tree like this aaa/bbb/ccc/<timestamp>.fileextension
When i want to see what uploads a user has, i'm doing this in the users corresponded directory
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
$inc = 0;
while (($file = readdir($dh)) !== false)
{
if (!is_dir($dir.$file))
{
$user_files[$inc]=$file;
$inc++;
}
}
closedir($dh);
}
}
my concern is: Is it efficient to get a users list of uploads like this or it would be faster if i stored each upload filename in a database like this:
upload_id, upload_filename, user_owner_id
(having index at user_owner_id) then just SELECT * FROM uploads WHERE user_owner_id = 1
Main question: What would be faster?
Also in the case of storing user uploads filenames in directory structure do i have to worry about lots of reading requests to disk (i heard SSD's have short life) -i doubt this concern has any practical impact but i would love an answer to this one just for educational purposes :)
Although i shouldn't care a lot about all this since the website is not high traffic, i m very curious about your answers since i dont have any idea about which of these two is considered better practice against the other :)
Upvotes: 0
Views: 58
Reputation: 1899
Some considerations (I'm no expert on SSD's and DB's, I just know how to utilise them):
You'll need to weight your options. With a small amount of files and low traffic a DB can be slower or just adds complexity.
With tens of thousands of files, security, plus more traffic blah blah blah, a DB would be indispensable IMO.
Hopefully that helps :)
Upvotes: 1