Home  >  Article  >  Backend Development  >  php sys_get_temp_dir - Returns the temporary file path_PHP tutorial

php sys_get_temp_dir - Returns the temporary file path_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:04:011524browse

Okay, without further ado, let’s take a look at the usage and implementation principle of this php sys_get_temp_dir - return temporary file path function.

sys_get_temp_dir
(PHP 5" = 5.2.1)

Okay, without further ado, let’s take a look at the usage and implementation principle of this php sys_get_temp_dir - return temporary file path function.

sys_get_temp_dir - Returns the directory path for temporary files

Description
String sys_get_temp_dir (void)
Returns the directory path to the PHP store's temporary files by default.

Return value
Returns the path to the temporary directory.

Example

Example #1 Example of sys_get_temp_dir()

Examples

Example #1 sys_get_temp_dir() example

// Create a temporary file in the temporary
// files directory using sys_get_temp_dir()
$temp_file = tempnam(sys_get_temp_dir(), 'Tux');

echo $temp_file;
?>
The above example will output something similar to:

C:WindowsTempTuxA318.tmp

How to implement this function:

if ( !function_exists('sys_get_temp_dir')) {
function sys_get_temp_dir() {
If (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
If (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
If (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
$tempfile=tempnam(uniqid(rand(),TRUE),'');
If (file_exists($tempfile)) {
Unlink($tempfile);
Return realpath(dirname($tempfile));
}
}
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630887.htmlTechArticleOkay, without further ado, let’s take a look at this php sys_get_temp_dir - return temporary file path function usage method and Let’s implement the principle. sys_get_temp_dir (PHP 5 = 5.2.1) Okay...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn