Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
in Q2A Core by

I am testing the new feature "save image to harddrive"  instead of blob.

As I see there are folders created in my upload folder defined in QA_BLOBS_DIRECTORY. As it seems these are arbitrary numbers from 000 to 184.

Two questions:

1. What is the mechansim behind the folder numbers?
okay, while writing this post, I found the answer in: function qa_get_blob_directory()
(subdirectories are named by the first 3 digits of $blobid)

2. How can I retrieve the path to the file on the harddisk using qa_blobs table?
This is important as I would like to update my image manager plugin accordingly.

Okay, number 2 can also be solved regarding number 1.

But there is another question now:

3. Why is "849092891028879862.png" saved in folder "008" and not "849" ?

Here is the substring return from function qa_get_blob_directory:
rtrim(QA_BLOBS_DIRECTORY, '/').'/'.substr(str_pad($blobid, 20, '0', STR_PAD_LEFT), 0, 3);

But what is happening here? STR_PAD_LEFT fills zeros to the left, 0, 3 takes the first 3 digits.... ?


Q2A version: 1.6.2
hi kai, have you solved this question meanwhile?

1 Answer

+1 vote
It's based on the fact that the latest possible random blobid has 20 digits, so the files are spread between the folders based on left-padding to 20 digits.
I think I still do not understand the reason behind that.

Example for another file: The blob id is "15015929639481993982", the folder is /150/ the filename is "15015929639481993982.jpeg".

Why do we need a folder here at all?
Folders are there to prevent there being too many files in a single directory, which can lead to all sorts of other problems at the OS level, not for Q2A.
Yes, I thought so. This is why I wrote the suggestion above. Using years as folders and month-day as subfolders would solve this as well. Plus it makes it easier for humans to find files, to handle files on the file system etc.

Link: http://www.question2answer.org/qa/36400/improving-the-image-upload-folder-file-structure