tmpfile

(PHP 4, PHP 5, PHP 7, PHP 8)

tmpfile建立一個(gè)臨時(shí)文件

說(shuō)明

tmpfile(): resource|false

以讀寫(xiě)(w+)模式創(chuàng)建一個(gè)具有唯一文件名的臨時(shí)文件,然后返回該文件的句柄。

文件在關(guān)閉后(例如,調(diào)用 fclose()tmpfile() 返回的文件句柄已無(wú)引用的情況)或腳本運(yùn)行結(jié)束后,會(huì)自動(dòng)刪除。

警告

如果腳本運(yùn)行被意外終止,可能不會(huì)刪除該臨時(shí)文件。

返回值

返回新文件的句柄,類(lèi)似于 fopen() 返回的文件句柄, 或者在失敗時(shí)返回 false

范例

示例 #1 tmpfile() 例子

<?php
$temp 
tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>

以上例程會(huì)輸出:

writing to tempfile

參見(jiàn)