This is an old revision of the document!
This RFC recommends a set of changes to the tempnam() standard function.
It's a common bug to forget to remove temporary files and after a period of time these may overpopulate the filesystem. TEMPNAM_REQUEST seeks to avoid this by building a mechanism to automatically clean up after scripts.
$fn = tempnam("/tmp/", "test-", TEMPNAM_REQUEST); file_put_contents($fn, "This is some data"); echo shell_exec("/usr/bin/someprog " . escapeshellarg($fn)); // No need to explicitly unlink($fn), since it will be cleaned up at request end
TEMPNAM_DIR expands the scope and usability of this function to whole directories of files while keeping the number of entities which need to be tracked low.
$file = tempnam("/tmp/", "", TEMPNAM_REQUEST); copy('http://www.php.net/get/php-5.4.9.tar.gz/from/us3.php.net/mirror', $file); $dir = tempnam("/tmp/", "", TEMPNAM_DIR | TEMPNAM_REQUEST); $dir = escapeshellarg($dir); $file = escapeshellarg($file); shell_exec("cd $dir && tar -zxf $file"); // tarball expanded into dir, both will be removed at request end
Although the existing function tmpfile() provides for the TEMPNAM_REQUEST cleanup functionality, it does not provide an actual filename which can be passed to external programs.
Coming soon, giving a chance to start discussion early.