wp_tempnam
函数
wp_tempnam ( $filename = '', $dir = '' )
- 参数
-
-
(string)
$filename
Optional. Filename to base the Unique file off. Default empty.- Required: 否
- Default: (empty)
-
(string)
$dir
Optional. Directory to store the file in. Default empty.- Required: 否
- Default: (empty)
-
(string)
- 返回值
-
- (string) A writable filename.
- 定义位置
-
-
wp-admin/includes/file.php
, line 659
-
wp-admin/includes/file.php
- 引入
- 2.6.0
- 弃用
- –
Returns a filename of a temporary unique file.
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.
function wp_tempnam( $filename = '', $dir = '' ) { if ( empty( $dir ) ) { $dir = get_temp_dir(); } if ( empty( $filename ) || in_array( $filename, array( '.', '/', '' ), true ) ) { $filename = uniqid(); } // Use the basename of the given file without the extension as the name for the temporary directory. $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 = $dir . wp_unique_filename( $dir, $temp_filename ); $fp = @fopen( $temp_filename, 'x' ); if ( ! $fp && is_writable( $dir ) && file_exists( $temp_filename ) ) { return wp_tempnam( $filename, $dir ); } if ( $fp ) { fclose( $fp ); } return $temp_filename; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。