2

On windows8 I got this with php 5.3:

echo sys_get_temp_dir();

output:

C:\Windows

Am I not understand something or it is a bug?

UPD

trying $_ENV:

<?php

var_export($_ENV);

output:

array ( )

Checking upload_tmp_dir:

<?php

echo ini_get('upload_tmp_dir');

output:

C:\Windows\Temp
Vitaly Dyatlov
  • 1,872
  • 14
  • 24

2 Answers2

2

Looking at the PHP source, it will call GetTempPath to determine the temp directory. According to the documentation, the windows directory C:\Windows is the last fallthrough option. You should check under which user profile PHP or its host process is running, maybe the environment needs some fixing.

Marcus Ilgner
  • 6,935
  • 2
  • 30
  • 44
  • everything is standard in my setup.. Apache 2.2 as a web service + php 5.3 with mod_fcgid as fcgi module. Cant find anything wrong in my php.ini. – Vitaly Dyatlov Mar 12 '13 at 12:43
  • you should re-check whether TMP and/or TEMP environment variables are set correctly on your system. If Apache runs as a Windows service, it is likely that the %USERPROFILE% temp dir isn't available, leaving only these two. Have you tried running a simple test-script from command line under your own user account that just outputs the value of sys_get_temp_dir() ? – Marcus Ilgner Mar 12 '13 at 12:54
  • also keep in mind this article when changing environment variables: http://support.microsoft.com/kb/821761 – Marcus Ilgner Mar 12 '13 at 12:55
  • 1
    Hm.. you were right about the console script: c:\Program Files (x86)\PHP>php -r "echo sys_get_temp_dir();" C:\Users\Vitaly\AppData\Local\Temp – Vitaly Dyatlov Mar 12 '13 at 13:00
1

Related to this PHP Bug (only CGI context?).

I have the same problem and the solution is to change the apache configuration to expose the TEMP system environment variable to PHP with this directive in apache configuration file (httpd.conf) :

PassEnv TEMP

Don't forget to activate the env_module, generally uncomment the line "LoadModule env_module modules/mod_env.so".

This solution fixes the result of these PHP functions: sys_get_temp_dir(), tempnam().

Jean Louis
  • 11
  • 3