Tablerate import fails when upload_tmp_dir is not related to sys_temp_dir #74
Description
From @jean-bernard-valentaten on December 28, 2017 10:34
Importing tablerates via backend fails with an error message like 'The file "/tmp/var/www/dist/var/upload/phpi1qs6p" doesn't exist' when PHP setting upload_tmp_dir
is set to anything that does not relate to setting sys_temp_dir
.
This is due to the first line of the private method \Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate::getCsvFile()
in which a directory reader for DirectoryList::SYS_TMP
is requsted.
Preconditions
- Magento 2.1.11 is installed
- PHP 7.0 FPM is used
- Nginx is used
- PHP setting
upload_tmp_dir
is set to a folder that does not relate to the folder defined bysys_temp_dir
Steps to reproduce
- In php.ini set
upload_tmp_dir
to an existing folder, e.g./var/php/upload
- Leave PHP setting
sys_temp_dir
unconfigured such that PHP defaults it, e.g./tmp
- In Backend navigate to Stores > Configuration > Sales > Shipping Methods
- Select any website as scope
- Open panel Table Rates
- On field Import select a file to upload
- Click on Save Config to trigger import
Expected result
- The tablerates should be imported
Actual result
- An error message pops up, stating something like 'The file "/tmp/var/php/upload/phpi1qs6p" doesn't exist'
When looking at \Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate::getCsvFile()
you'll notice the first line stating
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
This results in the sys_temp_dir being prepended to the actual file path when executing the line
return $tmpDirectory->openFile($path);
Copied from original issue: magento/magento2#12904