tmpfile()

创建于 2024-12-03 / 39
字体: [默认] [大] [更大]
❮ PHP 文件系统参考手册

实例

在读写(w+)模式下创建一个具有唯一名称的临时文件:

<?php
$temp = tmpfile();

fwrite($temp, "Testing, testing.");
//Rewind to the start of file
rewind($temp);
//Read 1k from file
echo fread($temp,1024);

//This removes the file
fclose($temp);
?>

上述代码的输出为:

Testing, testing.

定义和用法

tmpfile() 函数以读写(w+)模式建立一个具有唯一文件名的临时文件。

文件会在关闭后(用 fclose())自动被删除,或当脚本结束后。

注释: 该文件在关闭、使用 fclose() 或脚本结束时会自动删除。

提示: 另见 tempnam() 函数。

语法

tmpfile()

提示和注释

提示:参见 tempnam()


技术细节

返回值: 文件句柄(类似于 fopen() 为新文件返回的句柄),失败时为 FALSE
PHP 版本: 4.0+

❮ PHP 文件系统参考手册
0 人点赞过