php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47834 Documentation don't mention, that tempnam() falls back to OS TEMP...
Submitted: 2009-03-30 02:35 UTC Modified: 2009-04-21 05:31 UTC
From: whistl0r+phpbug at googlemail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.9 OS: win32 only - Windows
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: whistl0r+phpbug at googlemail dot com
New email:
PHP Version: OS:

 

 [2009-03-30 02:35 UTC] whistl0r+phpbug at googlemail dot com
Description:
------------
I wanted to check, how tempnam() handles file system limits.
On NTFS, just 65535 files per directory are allowed.

Reproduce code:
---------------
<?php
// Keep script alive
ignore_user_abort(1);
@set_time_limit(0);

$dir = 'C:\Test';
(if (!file_exists($dir))
{
	// Create Test directory
	mkdir($dir, null, true);
}

$i = 0;
while (tempnam($dir, 'Foobar'))
{
	$i++;
}

printf('%u files created', $i);

Expected result:
----------------
The script should stop, because tempnam() should return "false".
The function should return "false", because when 65535 files are in the 
specified directory, you reached a limit and aren't able to write to 
C:\Test anymore.

Actual result:
--------------
The script will keep running.
After the 65535. file is created in C:\Test, the function will ignore 
the specified directory and switch to %temp% (which is usually 
C:\Windows\Temp).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-31 13:02 UTC] whistl0r+phpbug at googlemail dot com
Hi,

okay - this is not a bug in PHP. It is a documentation problem.

The english version of the documentation says:

"If the directory does not exist, tempnam() may generate a file in the system's temporary directory, and return the name of that."

But that's wrong/not correct.

tempnam() will fall back to the system's temporary directory everytime it cannot write to the specified directory.

So I don't know in what circumstances this function will return "false".. but anyway... ;)
 [2009-04-21 02:54 UTC] fa@php.net
Verified and fixed in the documentation.

(btw, the directory after the full test directory was c:\Documents and Settings\user\Local Settings\Temp and not c:\windows\temp)
 [2009-04-21 05:31 UTC] whistl0r+phpbug at googlemail dot com
@ fa:

FYI:
It is Windows-dependent, how the folder is called.
<Windows Vista:
%userprofile%\Local Settings\Temp

>=Windows Vista:
%userprofile%\AppData\Local\Temp

And it is also user-dependent:
When you start the web server (e.g. Apache) as user, the path above is correct. But if you run it as service (LocalService account), then it points to %windir%\Temp
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of fa
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=7fcdd3d18c8a6fc31240fa7b6f6f85a33836a5b6
Log: fixed bug #47834
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 20:01:33 2025 UTC