I wonder where the tmp dir is set in the code of Drupal 8. Indeed the upload_tmp_dir value is not set in the php.ini and I have no access to change it.
Where in the code the value is defined and change it?
The logic for finding the proper OS temp directory is in FileSystem::getOsTemporaryDirectory
. This will try to use upload_tmp_dir
, otherwise default back to an OS value, like /tmp
.
This get used in file_directory_temp()
. If you read this function, you will see that the config value gets read first, and then it will try to get the OS default.
Personally, I set the filesystem paths in my settings.local.php file, so I can have a different value per environment, eg
$config['system.file']['path']['temporary'] = '/var/www/staging/tmp';
You also need to ensure that the file is writable by the webserver. Securing file permissions and ownership is the canonical reference on this, but in short something like
sudo chown -R www-data:www-data /var/www/staging/tmp
sudo find /var/www/staging/tmp -type f -exec chmod 664 {} \;
sudo find /var/www/staging/tmp -type d -exec chmod 2775 {} \;
will work.
You can find the setting in /admin/config/media/file-system. If you need that in php, you can use code like
Drupal::configFactory()->get('system.file');
The correct config for your tmp dir is system.file.path.temporary
. Check it in the UI with config-sync of simple config "system.file". Check class FileUploadResource
for an example.
You are wanting to hack the core. Which is evil. You simply can set another temporary directory on https://example.com/admin/config/media/file-system.
Via Drush.
$ drush -y config:set system.file path.temporary /Users/norman/Sites/temp
Alternatively but also quite evil is overriding PHP config from your settings.php. But note that some server setups may block PHP script files containing ini_set()
calls, resulting in a WSOD.
ini_set('upload_tmp_dir', '/tmp');
admin/reports/status
?