|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64410 sys_get_temp_dir() returns incorrect path
Submitted: 2013-03-12 08:37 UTC Modified: 2013-07-09 09:59 UTC
Avg. Score:4.5 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:1 (14.3%)
Same OS:3 (42.9%)
From: md dot xytop at gmail dot com Assigned:
Status: Wont fix Package: Filesystem function related
PHP Version: 5.3.22 OS: Windows 8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: md dot xytop at gmail dot com
New email:
PHP Version: OS:


 [2013-03-12 08:37 UTC] md dot xytop at gmail dot com
On Windows8 function sys_get_temp_dir() returns path 'C:\Windows' which is of 
course not correct

Test script:
echo sys_get_temp_dir();
// output: C:\Windows

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-19 07:29 UTC]
-Status: Open +Status: Feedback
 [2013-06-19 07:29 UTC]
Still experiencing this issue? Couldn't repro, it's always something like 
C:\Users\<user>\AppData\Local\Temp for me. Anything special in your setup?
 [2013-07-06 13:55 UTC] czarek dot tomczak at gmail dot com
I can confirm this issue, using PHP 5.4.10 via CGI. Recently two 
users of the PHP Desktop project have reported problems with the 
temp directory on Windows 8:

In both cases the temp directory returned by sys_get_temp_dir() 
is "C:\Windows".

Seems like the php version doesn't matter, it happens on php 5.3,
5.4, 5.5.
 [2013-07-08 18:57 UTC] czarek dot tomczak at gmail dot com
In the latest PHP 5.5.0 the temp directory on Windows 8 is "C:\Windows",
just confirmed by one of the users.
 [2013-07-09 09:59 UTC]
-Status: Feedback +Status: Wont fix
 [2013-07-09 09:59 UTC]
Ok, just tried it again with IIS+fastcgi+win8, it gives c:\windows\temp .

The windows implementation uses this API function to determine the temporary dir

According to that docs, c:\windows is the very last fallback when none of TMP, 
TEMP, USERPROFILE has worked. Conclusion - this is neither PHP nor Win API issue, 
but an environment one. For 5.4 one of those environment variables has to be set, 
for 5.5+ additionally sys_temp_dir is usable.
 [2016-05-23 12:46 UTC] biloo1 at caramail dot com
PHP 5.3.10 via CGI (Action application/x-httpd-php "/php/php-cgi.exe")
Apache 2.2.29
Windows 7 Pro SP1

sys_get_temp_dir() returns path 'C:\Windows'

My windows variables are set to '%SystemRoot%\TEMP' and '%USERPROFILE%\AppData\Local\Temp' BUT NOT TO 'C:\Windows' (%SystemRoot%)
 [2016-05-23 13:00 UTC] biloo1 at caramail dot com
In same context, the tempnam function reproduce this bug :

echo tempnam("", "");

returns: 'C:\Windows\A760.tmp'
 [2016-05-23 14:06 UTC] biloo1 at caramail dot com
I find the problem for me: Apache "don't show" the TEMP variable to PHP.

I add this in httpd.conf : PassEnv TEMP

Then the problem disappears.

Hope that helps !
 [2017-05-14 12:29 UTC] rafito dot dienola at gmail dot com
sys_get_temp_dir() return 'C:\Windows' on Windows Server 2012 R2 with PHP 7
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 22:01:28 2024 UTC