PHP tmpfile()関数
完全な PHP Filesystem リファレンスマニュアル
定義と使い方
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);
?>
$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 Filesystem リファレンスマニュアル その他の拡張