go to bug id or search bugs for
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
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
Add a Pull Request
An alternative would be to add a flag to tempnam(), e.g. tempnam ( string $dir , string $prefix, bool $create_a_directory ).