safe unique filename with no race condition
<p>Is this a safe way to move uploaded file with respect to race conditions?</p>

<pre><code>do { 
    $file = $path . "/" . uniqid() . '.' . $ext; 
    $fh = @fopen($file, 'x'); 
} while( ! $fh);
move_uploaded_file($src, $file);
</code></pre>

<p><strong>UPD</strong> Besides learning other ways of solving the problem I would like to know if this code is subject to race conditions. AFAIU, fopen with 'x' mode and move_uploaded_file are atomic, so no collision could be possible.</p>

<p>On top of that and with regards to "uniqid will suffice", <a href="http://www.php.net/manual/en/function.tempnam.php#98232" rel="nofollow">several</a> <a href="http://www.php.net/manual/en/function.tempnam.php#97086" rel="nofollow">people</a> in <a href="http://www.php.net/manual/en/function.tempnam.php#37762" rel="nofollow">comments</a> to tempnam stated necessity of using fopen with 'x' mode to avoid race conditions. Do they overly paranoid? I think, having safer solution is better, if it doesn't make code significantly complex.</p>
