返回介绍

wp_tempnam()

发布于 2017-09-11 12:59:05 字数 3474 浏览 1031 评论 0 收藏 0

wp_tempnam( string $filename = '',  string $dir = '' )

Returns a filename of a Temporary unique file.


description

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.


参数

$filename

(string) (Optional) Filename to base the Unique file off.

Default value: ''

$dir

(string) (Optional) Directory to store the file in.

Default value: ''


返回值

(string) a writable filename


源代码

File: wp-admin/includes/file.php

function wp_tempnam( $filename = '', $dir = '' ) {
	if ( empty( $dir ) ) {
		$dir = get_temp_dir();
	}

	if ( empty( $filename ) || '.' == $filename || '/' == $filename || '\\' == $filename ) {
		$filename = time();
	}

	// 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;
}

更新日志

Versiondescription
2.6.0Introduced.

相关函数

Uses

  • wp-admin/includes/file.php: wp_tempnam()
  • wp-includes/pluggable.php: wp_generate_password()
  • wp-includes/functions.php: get_temp_dir()
  • wp-includes/functions.php: wp_unique_filename()

Used By

  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::import_theme_starter_content()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::upload_from_data()
  • wp-admin/includes/class-wp-filesystem-ftpext.php: WP_Filesystem_FTPext::get_contents()
  • wp-admin/includes/class-wp-filesystem-ftpext.php: WP_Filesystem_FTPext::put_contents()
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php: WP_Filesystem_ftpsockets::get_contents()
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php: WP_Filesystem_ftpsockets::put_contents()
  • wp-admin/includes/file.php: wp_tempnam()
  • wp-admin/includes/file.php: download_url()
  • Show 3 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文