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.
This is a common solution for this problem.
For get temportantly file (enviroment independent) use PHP function:
resource tmpfile ( void )
Documemtation for it you can find at http://pl.php.net/manual/en/function.tmpfile.php
This function returning handle to your new clean tempfile.
But if your using this function you must copy file before you close handle to it because this file was removed when you call fclose(handle)
. To get assurance of file buffer is clean you can at end call fflush(handle)
.
Or if you don't want use tmpfile(void)
function you can do this manualy.
string tempnam ( string $dir, string $prefix )
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:
string sys_get_temp_dir ( void )
Then when you have self tempfile, write to it upload data and close.
Copy this file to your final location using:
bool copy ( string $source, string $dest [, resource $context ] )
And delete your tempfile to get clean in your enviroment calling:
bool unlink ( string $filename [, resource $context ] )