 <p>You can in upload script use a temportantly file (in temportantly directory) and if upload was finished you can simple move file to your final location with good filename.</p> <p>This is a common solution for this problem.</p> <p>For get temportantly file (enviroment independent) use PHP function:</p> <pre><code>resource tmpfile ( void ) </code></pre> <p>Documemtation for it you can find at <a href="http://pl.php.net/manual/en/function.tmpfile.php" rel="nofollow noreferrer">http://pl.php.net/manual/en/function.tmpfile.php</a> This function returning handle to your new clean tempfile.</p> <p>But if your using this function you must copy file before you close handle to it because this file was removed when you call <code>fclose(handle)</code>. To get assurance of file buffer is clean you can at end call <code>fflush(handle)</code>.</p> <hr> <p>Or if you don't want use <code>tmpfile(void)</code> function you can do this manualy.</p> <pre><code>string tempnam ( string $dir, string $prefix ) </code></pre> <p>Prefix is a prefix to your files to easly group her to delete or something. Call this function to get unique file in typed directory, as directory get you temp directory in your enviroment, you can get this by calling:</p> <pre><code>string sys_get_temp_dir ( void ) </code></pre> <p>Then when you have self tempfile, write to it upload data and close. Copy this file to your final location using:</p> <pre><code>bool copy ( string $source, string $dest [, resource $context ] ) </code></pre> <p>And delete your tempfile to get clean in your enviroment calling: </p> <pre><code>bool unlink ( string $filename [, resource $context ] ) </code></pre>