|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52074 RFE: tempdir() countrpart to tempnam()
Submitted: 2010-06-13 02:57 UTC Modified: 2021-08-27 15:51 UTC
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: php at richardneill dot org Assigned: cmb (profile)
Status: Wont fix Package: Directory function related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at richardneill dot org
New email:
PHP Version: OS:


 [2010-06-13 02:57 UTC] php at richardneill dot org
It would be really useful to have the ability to create a tempdir, with a 
unique name, which we know we can write to, and will be automatically cleaned 

For example, if I want to run an external command (with exec() ) which will 
write to a file, where:

  - it must be known that file-creation can succeed
  - the file does not exist at the moment

Test script:
Some applications will refuse to overwrite an existing file (that we created with tempnam()), because they don't want to clobber it. What we effectively need is a race-free way to assign a temp-filename without actually creating the file.  Using tmpfile() doesn't help, because we can't pass a file-handle to php's exec().


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-30 10:26 UTC] phpbugs at canavan dot de
An alternative would be to add a flag to tempnam(), e.g. tempnam ( string $dir , string $prefix, bool $create_a_directory ).
 [2021-08-27 15:51 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-08-27 15:51 UTC]
> What we effectively need is a race-free way to assign a
> temp-filename without actually creating the file.

How would that be possible in the general case?  Even tempnam(3)
is not without race-condition; a function that would return the
name of a temporary directory, is as well.

Given that this rather doubtful request had not much traction for
more than ten years, I'm closing as WONTFIX.

Feel free to pursue the RFC process[1], if you want to see this
feature implemented.

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 21:01:30 2024 UTC