In our structured Drupal training program, we teach the "right way" to do things. We listen to our support team of client advisors who see all the permutations of "you're doing it wrong" in Drupal, and make sure we're leading learners in the right direction. When there's something particularly essential we use words like "Important" and set off warnings with a little exclamation mark icon. What we don't do is surround particular instruction in skulls and cross-bones and "Ye shall not pass" signs explaining the hells that will befall you if you don't do something a certain way. Because everything in Drupal is optional, and up to you.
Take, for example, the file field "File directory" path settings. If you didn't know it could lead you to potential disaster, you might think this "optional" setting is something you could just overlook. Many clients add file fields, and never complete this configuration. With multiple content types, files on taxonomy terms or other entities, it means ALL the uploaded files across the site are going into the same directory.
In fact, we encounter this problem while supporting some of the biggest and busiest websites with our hosting business. "How many files can you store in a directory" depends on your server software and configuration. Like the proverbial "clowns in a car" trick, you don't want to attempt to reach that upper limit. While the technical upper limits may be high, you can notice performance implications with 1000 or 100,000 files. This could be when you try to load a directory, or even display an image from a directory. You may never think you'll get up to that many files, but if you have users generating content, you can get surprised.
Especially if you haven't let Drupal handle the file referencing and management, remediating the problem is painfully slow. For example, adding inline references to images on your server, instead of using modules like Media which use tokens to place images inline. My colleague, Devin Carlson, (who is very knowledgeable about the file system in Drupal 7) explained it took him 1-2 weeks to fix a similar problem on a client site. He used the Migrate module, wrote custom scripts and tested over and over again to ensure all the files were moved and all internal inline references were updated.
How to add file upload fields to Drupal the right way
In terms of file path management, you can do three things:
- Even if you don't install another module you can add a prefix to each instance of a file field. For example, add the entity name (content type, taxonomy term name).
- Use the Token module and you can use the current date as a dynamic configuration.
- Use the File (Field) Paths module for ALL the options. With this module, you can access all node tokens, such as the date when the node was created or the author. The File field paths module also lets you rename the files.
If you're new to Drupal, I've got a more complete tutorial for you. In my live online walkthrough last week, I walked through all the basics of adding file fields, how to configure private or public download methods, and other essentials. I mentioned the very important modules you should already be using, and I talked about additional modules you can use to improve the process, and some future friendly tips about what is being worked on for media and file management in Drupal 8. You can watch it here. You can also flip through the slides here.