1

I'm building a website which holds its images in relevant folder, but I was wondering how to structure the folder paths ( month/year/ or just year/ )

I will be getting the images via php, so the scripting will look like:

files/cover_photo/$year/$month/$id.jpg

I don't really know how many images I'm going to be posting but was wondering how many images is a comfortable number in each folder if they are going to be selected using the PHP script above.

I don't want to risk slowing my site down by having too many images per directory, but at the same time I don't want to have too many directories with few files inside.

Can anyone give me any advice?

1
  • If you are asking about the filesystem path, then the hard "limit" is imposed by the OS, not PHP.
    – MrWhite
    Commented Jun 5, 2016 at 10:23

1 Answer 1

2

There is not really a "right answer" to this.

Sorting by year/month is not a bad option, because it's easy to implement and it scales well.

There's no need to worry about empty directories though - just create the directories when you need them (i.e. the first time there's an upload in that year or month).

This is the way Wordpress does it.

2
  • 1
    Thanks Tim. I'll go with the year/month option as it makes more sense to me that way anyway! Commented Jun 5, 2016 at 10:12
  • No problem. :) I should note that you can accept an answer if it has helped you by clicking the check mark to the left of the answer (you don't have to do this, but it does help future users plus gives some rep to the person who has answered - I just mention it because I notice you haven't accepted an answer yet so might not know how it works). There's some more info in the help centre here and here. Good luck with the project!
    – Tim Malone
    Commented Jun 5, 2016 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.