PHP tmpfile() 関数


❮ 完全な PHP ファイルシステム・リファレンス

定義と用法

tmpfile() 関数は、読み書き可能(w+)モードでユニークな名前を持つ一時ファイルを作成します。

構文

tmpfile()

チップスと注意

注: 一時ファイルは、fclose()で閉じたり、スクリプトが終了したときに自動的に削除されます。

チップ:tempnam()も見てください。


<?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.

❮ 完全な PHP ファイルシステム・リファレンス