Skip to main content

Drupal Error - The specified file 'temporary://filename' (Fix)

Error Message: The specified file 'temporary://filename' could not be copied because the destination directory.

This Drupal error can happen from two reasons

1. Temp Folder in Unix system is not set and matched in your settings.php

Drupal reads from your settings.php file to populate:

Public file system path
sites/default/files

Public file base URL
https://<google>.com/sites/default/files

Optimized assets file system path: sites/default/files

Private file system path
<path to private file system outside>

Temporary directory: /tmp

a) Make sure that the Temporary Directory exists in your Unix system
b) There should be an .htaccess file in the directory. It shows that Drupal can access it. You don't need any special permission or change ownership or write permission for the default /tmp folder. It is writeable by default
c) Double check the name of the temporary directory

2. The Copying permission to the Drupal files directory is the issue

a.    Change permission of the files directory. Don't run chown command as a root. use sudo instead

sudo chown -R <username>:apache files

Now you should see a new error like "User warning: mkdir(): Permission Denied in Drupal\Component\PhpStorage\FileStorage->createDirectory()"

This means that the error has progressed from a cryptic temporary directory to a direct permission denied error. Your apache installation cannot create css or js directories inside your files folder. So let us go to the next step

b. Change write permission of the files directory and all child directories

***Don't use 777***** All errors will go away but you have opened up your site to new vulnerabilities

First check the permission with stat command

stat files

if it is 755 or any permission lower than that, then the error is likely from the permission

Number system

R - Read (4)
W - Write (2)
X- Execute (1)

7 - 4+2+1 RWX (Group Owner have full permission)
7 - 4+2+1 RX (Unix user under which you have installed the Drupal Installation have full permission)
5 - 4+1 (RX) (public have only read and execute permission. No write permission)

Note: The permission that you need is 775 for your files folder and its child directories

chmod -R 775 files

-R will recursively apply the permission to all child directories

Now you should see css and js folders created under the files directory and your Drupal sites should work as expected

3. htaccess permission in /tmp

In case both 1 and 2 didn't work

go to /tmp folder as a root and check for an .htaccess file

add this in the .htaccess file

# Turn off all options we don't need.
Options -Indexes -ExecCGI -Includes -MultiViews

# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
 # Override the handler again if we're run later in the evaluation list.
 SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php.c>
 php_flag engine off
</IfModule>

4. SELinux permission

If 1, 2 and 3 didn't resolve the issue, SELinux might be preventing apache user from writing to the files folder. Run the following command

sudo chcon -R -t httpd_sys_rw_content_t /path/to/sites/default/files

 

 

 

Technical
Drupal