php.net |  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
Votes:8
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
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:
----------------
C:\Windows\Temp

Actual result:
--------------
C:\Windows

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-19 07:29 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2013-06-19 07:29 UTC] ab@php.net
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:

https://code.google.com/p/phpdesktop/issues/detail?id=23
https://code.google.com/p/phpdesktop/issues/detail?id=39

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] ab@php.net
-Status: Feedback +Status: Wont fix
 [2013-07-09 09:59 UTC] ab@php.net
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
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx

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-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 13:01:30 2025 UTC