php.net |  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
Votes:1
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
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: info at silisoftware dot com
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-05 10:31 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [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:
	\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.
 [2008-08-21 20:39 UTC] pajoye@php.net
Fixed in 5.3.x
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 19:01:28 2024 UTC