|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36290 tempnam() creates file on wrong drive
Submitted: 2006-02-05 02:19 UTC Modified: 2008-08-21 20:39 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: info at silisoftware dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.4.2 OS: Windows XP Pro SP2
Private report: No CVE-ID: None
 [2006-02-05 02:19 UTC] info at silisoftware dot com
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:


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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-05 10:31 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-02-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-06-23 11:47 UTC] hanskrentel at yahoo dot de
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:

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.<<

so the behavior is correct per definition but useless and i guess not intended.
 [2008-08-21 20:39 UTC]
Fixed in 5.3.x
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 07:05:52 2023 UTC