I want to know where Drupal (or its modules) create temporary files. Are they put in sites/default?

I'm especially talking about Drupal 6.

  • Modules can try to create temp files anywhere on the drupal site, but will only succeed where the server configuration allows it. See: drupal.org/node/244924
    – August1914
    May 12, 2012 at 16:49

2 Answers 2


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.

  • does your answer apply to Drupal 6 or just Drupal 7?
    – iStryker
    Jul 22, 2011 at 20:31
  • 2
    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.
    – apaderno
    Jul 22, 2011 at 20:53

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.

  • 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, 2011 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, 2011 at 20:26
  • @iStryker Today I saw an error in that reports/status section of my website saying "the files directory is not protected" and suggested drupal.org/forum/newsletters/… to create .htaccess in the files directory and also put "Deny from all" in .htaccess found in temporary files directory for code execution prevention. I am confused. Is it a 'tmp' folder some where or every modules has its own folder? DO I have to put .htaccess file in every folder?
    – Umair
    Apr 30, 2018 at 6:25

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.