$temp_filename =
basename( $filename );
$temp_filename =
preg_replace( '|\.[^.]*$|', '',
$temp_filename );
// If the folder is falsey, use its parent directory name instead.
if ( !
$temp_filename ) { return wp_tempnam( dirname( $filename ),
$dir );
} // Suffix some random data to avoid filename conflicts.
$temp_filename .= '-' .
wp_generate_password( 6, false
);
$temp_filename .= '.tmp';
$temp_filename =
wp_unique_filename( $dir,
$temp_filename );
/*
* Filesystems typically have a limit of 255 characters for a filename.
*
* If the generated unique filename exceeds this, truncate the initial
* filename and try again.
*
* As it's possible that the truncated filename may exist, producing a
* suffix of "-1" or "-10" which could exceed the limit again, truncate
* it to 252 instead.
*/