Home  >  Article  >  Daily Programming  >  How to get the directory path of temporary files in PHP

How to get the directory path of temporary files in PHP

藏色散人
藏色散人Original
2019-02-16 15:25:4814581browse

PHP obtains the directory path of the temporary file, which can be achieved through the tempnam() and sys_get_temp_dir() functions.

How to get the directory path of temporary files in PHP

Below we combine simple code examples to introduce how to obtain the directory path of temporary files in PHP.

The code example is as follows:

<?php
$temp_file = tempnam(sys_get_temp_dir(), &#39;aaa&#39;);

echo $temp_file."\n";

The output is as follows:

How to get the directory path of temporary files in PHP

Function introduction:

The tempnam() function is used to create a file with a unique file name.

tempnam ( string $dir , string $prefix ) : string

Create a file with a unique file name in the specified directory. If the directory does not exist, tempnam() generates a file in the system temporary directory and returns its filename.

The parameter dir indicates the directory in which the temporary file name will be created, and prefix indicates the prefix of the temporary file.

Note: Windows only uses the first three characters of the prefix.

The return value returns the new temporary file name, and returns FALSE on error.

sys_get_temp_dir() function Returns the directory used for temporary files

sys_get_temp_dir ( void ) : string

Returns the path to the default directory where PHP stores temporary files.

Return value returns the path of the temporary directory.

This article is an introduction to the method of obtaining the directory path of temporary files in PHP. I hope it will be helpful to friends in need!

The above is the detailed content of How to get the directory path of temporary files in PHP. For more information, please follow other related articles on the PHP Chinese website!

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