1.2.1351. Use System Tmp¶
It is recommended to avoid hardcoding the temporary file. It is better to rely on the system’s temporary folder, which is accessible with sys_get_temp_dir().
<?php
// Where the tmp is :
file_put_contents(sys_get_temp_dir().'/tempFile.txt', $content);
// Avoid hard-coding tmp folder :
// On Linux-like systems
file_put_contents('/tmp/tempFile.txt', $content);
// On Windows systems
file_put_contents('C:\WINDOWS\TEMP\tempFile.txt', $content);
?>
See also PHP: When is /tmp not /tmp?.
1.2.1351.1. Suggestions¶
Do not hardcode the temporary file, use the system’s
1.2.1351.2. Specs¶
Short name |
Structures/UseSystemTmp |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Available in |