怎么用PHP创建唯一的临时文件

WBOY
Release: 2016-06-13 13:17:56
Original
1087 people have browsed it

如何用PHP创建唯一的临时文件

$tmpfile = tempnam( getcwd()."/", "TMP" );    // 创建唯一的临时文件
Copy after login

tempnam -- 建立一个具有唯一文件名的文件
语法:string tempnam ( string dir, string prefix )
tempnam是在指定的目录下建立以prefix为前缀的唯一的临时文件(TMP(*).tmp),文件名的后缀名为tmp,这边传递的前缀(prefix),长度最大为3,如果超过了3,后面的将被截断。比如,你写TEMP,只取TEM作为前缀。
另外,getcwd函数是取得当前工作目录(get current work dir)。

// current directory
echo getcwd() . "\n";   //echo /home/didou
chdir('cvs');
// current directory
echo getcwd() . "\n";   //echo /home/didou/cvs
Copy after login
?
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!