Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I want to know where Drupal (or its modules/plugins) create temp files. Is it sites/default?

I'm especially talking about D6.2

share|improve this question

migrated from stackoverflow.com Jul 22 '11 at 18:26

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers 3

up vote 12 down vote accepted

Files are created in the directory whose name is returned from file_directory_temp() which returns:

  • The value of the Drupal variable "file_temporary_path," which is set from the setting page on admin/config/media/file-system (Drupal 7) or admin/settings/file-system (Drupal 6).

  • If that Drupal variable is not set, then the function checks one of the following directories; if one of those directories exists, then it is returned (and used).

    • the directory returned from ini_get('upload_tmp_dir')
    • on Windows, the directories "c:\windows\temp" and "c:\winnt\temp."
    • on OSes different from Windows, the directory "/tmp."
    • on PHP version 5.2.1 or higher, the directory returned by sys_get_temp_dir().
  • If the variable "file_temporary_path" is not set, and the directories I listed in the previous point don't exist, or are not writable, the function uses the value of the Drupal variable "file_public_path"; by default that directory has the value conf_path() . '/files' that is the directory "files" contained in the directory containing the setting.php file used for the Drupal site.

The function set the variable "file_temporary_path" to the directory it found.

As far as I know, any module opens temporary files using a path starting with "temporary://" (available only in Drupal 7 and higher) or uses file_directory_temp(). The directory returned from file_directory_temp() can change from system to system, but modules always use that directory.

Drupal modules don't have the permission to write the directory containing the modules; it's quite difficult a module uses that directory to create temporary files. If you find a module that uses the directory containing the modules (or any sub-directory of that directory) report that as a bug.

share|improve this answer
    
does your answer apply to Drupal 6 or just Drupal 7? –  iStryker Jul 22 '11 at 20:31
1  
It applies to both, as file_directory_temp() is defined in Drupal 6 too, and the code for the function doesn't change passing from Drupal 6 to Drupal 7. –  kiamlaluno Jul 22 '11 at 20:53
add comment

The setting page at admin/settings/file-system contains settings for the directory used for temporary files.

Some modules could choose a different directory for temporary files. There's no standard folder location.

For example, the ctools module will create temporary cached files in the /sites/default/files/ctools directory. So it may vary.

share|improve this answer
    
Are you saying that a module can create temp file anywhere in the drupal site? Can it also create in root/themes root/modules etc? –  AgA Jul 22 '11 at 18:59
    
Yes, modules can create temporary files anywhere. They usually keep them in one folder, as does ctools. From my experience modules creating their own temp directory is rare. Most modules uses the default temporary directory Chris talks about. –  iStryker Jul 22 '11 at 20:26
add comment

Modules can try to create temp files anywhere on the drupal site, but will only succeed where the server configuration allows it. See: http://drupal.org/node/244924

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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