|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-02-05 02:19 UTC] info at silisoftware dot com
Description:
------------
tempnam() returns a temp filename, and creates the file. However, it creates it on the wrong drive. For example:
$tempname = tempnam('', 'foo');
echo $tempname.'<br>';
echo realpath($tempname).'<br>';
This outputs:
\foo49.tmp
e:\foo49.tmp
Notice the returned filename has no drive letter. The file is created (to prevent race condition) in C:\ but realpath() resolves that to E:\ (the last drive letter of physical harddrives in this system).
For reference:
getenv('TMP') == 'C:\WINDOWS\TEMP'
getenv('TMPDIR') == ''
Reproduce code:
---------------
$tempname = tempnam('', 'foo');
echo $tempname.'<br>';
echo realpath($tempname).'<br>';
Expected result:
----------------
c:\foo49.tmp
c:\foo49.tmp
Actual result:
--------------
\foo49.tmp
e:\foo49.tmp
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 04:00:01 2025 UTC |
I just checked this out on PHP Version 5.1.2 and the behavior for me is the same, so this was not fixed. reproduced with: $tempname = tempnam('', 'foo'); echo $tempname.'<br>'; echo realpath($tempname).'<br>'; output in my case: \foo5E0.tmp d:\foo5E0.tmp d:\ is not my tempdir anyway this function behaves inconsisten per default as discribben in the current online documentaion: >>Creates a file with a unique filename in the specified directory. If the directory does not exist, tempnam() may generate a file in the system's temporary directory, and return the name of that.<< http://www.php.net/manual/en/function.tempnam.php so the behavior is correct per definition but useless and i guess not intended.