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

I'd like to store the uploaded images on disk rather than in the database. To do this, I created a folder named "files" in the q2a root and then put the line below in qa-config.php:

define('QA_BLOBS_DIRECTORY', 'files');

It works but my problem is that it stores every image (or any other uploaded files) in separate randomly-named folders rather than in the root of that "files" folder. See the screenshot below in which there are multiple folders:

So how can I store all uploaded files in the "files" folder rather than in multiple folders in it?

Q2A version: 1.6.3

3 Answers

+1 vote
selected by
Best answer

I think the issue here is just a matter of abstraction :) You claim that having files stored that way is a "problem". However, you haven't mentioned WHY you consider it as problem.

Just doing some guessing, your intention is to browse those directories. If that is the case, then that is the problem. That directory is not there to be browsed but rather to be internally and efficiently used by Q2A.

If you need to browse the blobs (which by the way, they are not just uploaded images in posts but also avatars), then you must use a higher level of abstraction to do so. You can do that by means of a plugin that fetches the required information from the core. In fact, that plugin wouldn't even care about how the blobs are stored as the Q2A core is smart enough to abstract the plugin from that.

+1 vote
You will be able to change the naming rule of folders and files by plugin or core hack. However, there is a limit to the number of files that can be stored in one folder. Therefore, you should not save all files in one folder.
@sama55: Why is there a limit to the number of files that can be stored in one folder?
Although theoretically there may be no upper limit, it is considered that a substantial (for example, the operation performance and command) problems may occur. Please search on Google. You will be able to obtain a variety of information.
+1 vote
You bring up a good point. I also find it hard to orientate with this structure.

I suggested once to use a folder structure like \YEAR\MONTH\DATE or \YEAR\MONTH\ - that would overcome the problem of too many files in one folder.

But no changes have been integrated since then.

Read here as well: http://www.question2answer.org/qa/28773/getting-the-path-to-image-file-from-qa_blob