im developing a forum and users will be able to upload pictures.
i wonder how i should organize the folders for this?
should they be sorted by threads or users? but how will they then be organized within these folders?
and how could i couple some post’s pictures to the database entry? eg, if the post got 5 images uploaded, should i have a one-to-many (one thread – many pictures) relationship where the pic entries contain the name of the pictures?
i’ve never done this before.
would be great if someone could give me some piece of advice.
Do you expect to handle/copy/transfer/delete a thread’s worth of images in one go? If so, it may make sense to create a folder for each thread. Otherwise there would be no particular benefit. In fact it could be a drawback… for example if you can move posts from one thread to another or merge threads, you’d then have to write extra code to move the image files.
Yes, or maybe one post many pictures?
If you remember the filenames of the uploaded files, it should only be for display purposes in the thread. Don’t use a user-submitted filename as a filename on your server’s filesystem. This risks clashes when two users upload files with the same name, and anyway ‘sanitising’ user names for security is difficult to get right.
Better, give each database picture row a primary key, and use that key to name the file, for example
5272.jpeg. You should also really be serving the uploaded files from a different hostname, otherwise there are all sorts of cross-site-scripting risks.See this question for some background. Dealing with user-uploaded files securely is not at all easy, and almost every file-upload tutorial out there is full of security holes.