wp_tempnam()
Returns a filename of a Temporary unique file. Please note that the calling function must unlink() this itself.
Please note that the calling function must unlink() this itself.
The filename is based off the passed parameter or defaults to the current unix timestamp, while the directory can either be passed as well, or by leaving it blank, default to a writable temporary directory.
Used By: download_url()
1 time — 0.000405 sec (fast) | 50000 times — 5.08 sec (fast) | PHP 7.1.11, WP 4.9.5
No Hooks.
Return
String
. A writable filename.
Usage
wp_tempnam( $filename, $dir );
- $filename(string)
- Filename to base the Unique file off.
Default: '' - $dir(string)
- Directory to store the file in.
Default: ''
Examples
#1 Example of what the function outputs
require_once ABSPATH . 'wp-admin/includes/file.php'; $filename = wp_tempnam(); //> /tmp/1524879129-OkwJkv.tmp // modify the file and do something with it unlink( $filename ); // delete the file
More examples:
$filename = wp_tempnam( 'my_log_file' ); //> /tmp/my_log_file-BmwSQw.tmp unlink( $filename ); $filename = wp_tempnam( 'my_log_file.log' ); //> /tmp/my_log_file-AreTYU.tmp unlink( $filename ); $filename = wp_tempnam( '', $_SERVER['DOCUMENT_ROOT'].'/' ); //> /home/example.com/public_html/1524879213-ieQsRX.tmp unlink( $filename );
Changelog
Since 2.6.0 | Introduced. |