Ok, implemented the change on my phpBB 3.0 board earlier, now porting it to my 3.2 dev instance.
My board has already reached 500k attachments, so over a million files in one folder (including thumbnails) would be... I'm not sure if even possible for the filesystem, and would certainly affect the performance of the site.
So, subfolders.
Method of storage: 2-level folder structure based on the first 4 symbols of the attachment hash.
E.g. for hash 7b485f3c846e35334bc28c61c586162a its files are stored as follows:
Code: Select all
files/7b/48/234_7b485f3c846e35334bc28c61c586162a
files/7b/48/thumb_234_7b485f3c846e35334bc28c61c586162a
So, upload works as usual (files placed to "files/"), but on download, the new location in subfolder is checked and files get moved if they are not present in their respective subfolder.
The benefit of this method is that it provides seamless backward compatibility with the existing method of storage and does not require any conversion; files get moved to subfolders gradually, one by one, as they are downloaded by users.
Also, I had to amend the attachment deletion code.
Files changed:
Code: Select all
forum/includes/functions_download.php
forum/phpbb/attachment/delete.php
It does not fully comply with coding guidelines ATM, just as a proof of concept.
BTW, in my patch, when an image file is moved to subfolder, its orientation also gets fixed to prevent some browsers from showing portrait photos as landscape; you can just ignore this piece of code for now.
Question: is this a feasible solution? Is it possible to get it implemented in core?