I was wondering if there is some sort of convention for where to place files downloaded to the server by a module? To be more specific, one of the things my module does is download tarballs and extracts them into a directory.

If I had to assume, I'd say the the following:

  • The tarballs should get downloaded into the Drupal temp directory.
  • The extracted files should be place into a directory called module_name in the Drupal files directory.
$temp_dir = file_directory_temp();
$dest_dir = file_directory_path() . DIRECTORY_SEPARATOR . $module_name;

I think I should do this because for a couple of reasons:

  • I can't assume any other directories are writable by Drupal.
    • Even though my module does something which many purport as being complicated, I want the default setup to be setup such that most Drupal installations require no, or very little, changes to their directory and file permissions. If a site administrator wants the files to go somewhere else, then I think the best option would be offer a wizard for moving or changing paths. Then, the administrator can be guided on what changes need to made, if any, to the file system.
  • I can use Drupals file handling functions. (I could use them anyway, but this way would feel more elegant.)

Is this a correct assumption? Or, is there some different convention I should follow.

Comments

agentrickard’s picture

What you describe is the standard way of using the file APIs for Drupal. The only gotcha -- if you plan to release your work -- is making the system you write work in both public and private file mode.

See http://api.drupal.org/api/group/file/6 for the API library. And see http://api.drupal.org/api/function/hook_file_download/6 for private file handling rules.

--
http://ken.therickards.com