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

How to get the directory path of temporary files in PHP

Feb 16, 2019 pm 03:25 PM

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";
Copy after login

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
Copy after login

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
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)