|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39421 tempnam() unexpected behavior
Submitted: 2006-11-08 06:19 UTC Modified: 2006-11-08 17:16 UTC
From: ruslan_y at list dot ru Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.2.0 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2006-11-08 06:19 UTC] ruslan_y at list dot ru
After the upgrade from old php 4.x to 5.2.0. Some of my web scripts stop working. One of the reason is the changes in tempnam() behavior which stop working with local path like "./dir" or "dir/" and force me to add system temporary folder to open_basedir path.

Windows XP SP2 | PHP 5.2.0 | Apache 2.0.55 (+ php5apache2.dll)

P.S. php.exe works as expected (except DOCUMENT_ROOT is null) 
(php.exe -q 1.php)

Reproduce code:
if (!is_dir('2')) mkdir('2');

$tmpfname1 = tempnam('2/', "FOO");
$tmpfname2 = tempnam('./2/', "FOO");
$tmpfname3 = tempnam('2\\', "FOO");
$tmpfname4 = tempnam('.\2', "FOO");
$tmpfname5 = tempnam('C:\root\www\host2\www\2\\', "FOO");

echo '<pre>'."\n";
echo '$tmpfname1 = '.$tmpfname1."\n";
echo '$tmpfname2 = '.$tmpfname2."\n";
echo '$tmpfname3 = '.$tmpfname3."\n";
echo '$tmpfname4 = '.$tmpfname4."\n";
echo '$tmpfname5 = '.$tmpfname5."\n";
echo '</pre>'."\n";

Expected result:
A new directory "2" and five files in it.

DOCUMENT_ROOT = C:/root/www/host2/www
$tmpfname1 = 2/FOOFA.tmp
$tmpfname2 = ./2/FOOFB.tmp
$tmpfname3 = 2\FOOFC.tmp
$tmpfname4 = .\2\FOOFD.tmp
$tmpfname5 = C:\root\www\host2\www\2\FOOFE.tmp

Actual result:
A new directory "2" and only one file in it. all other files in the windows temp folder.

DOCUMENT_ROOT = C:/root/www/host2/www
$tmpfname1 = C:\WINDOWS\TEMP\FOO10A.tmp
$tmpfname2 = C:\WINDOWS\TEMP\FOO10B.tmp
$tmpfname3 = C:\WINDOWS\TEMP\FOO10C.tmp
$tmpfname4 = C:\WINDOWS\TEMP\FOO10D.tmp
$tmpfname5 = C:\root\www\host2\www\2\FOO10E.tmp


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-08 16:47 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

As of PHP 5.2.0 tempnam() enforces open_basedir limit, which 
is why the temporary directory needs to be within the 
 [2006-11-08 17:16 UTC] ruslan_y at list dot ru
I'm sorry, but I'm was not talking about open_basedir itself but about some changes of using local path in tempnam() function then php is an apache module!

You can see in the example that it's a really different as cli and sapi module!

(php -q 1.php)
$tmpfname3 = 2\FOOFC.tmp
$tmpfname3 = C:\WINDOWS\TEMP\FOO10C.tmp

Why It so different? Why I cannot get an expected result? That's the question!
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Nov 28 11:05:53 2022 UTC