Watch out using a blank $dir as a "trick" to create temporary files in the system temporary directory.
<?php
$tmpfname = tempnam('', 'FOO'); // not good
?>
If an open_basedir restriction is in effect, the trick will not work. You will get a warning message like
Warning: tempnam() [function.tempnam]: open_basedir restriction in effect.
File() is not within the allowed path(s): (/var/www/vhosts/example.com/httpdocs:/tmp)
What works is this:
<?php
$tmpfname = tempnam(sys_get_temp_dir(), 'FOO'); // good
?>