メインコンテンツまでスキップ
Version: Fegg 5.x

File::writeFile

ファイルにデータを書き込みます

説明​

public bool File::writeFile( string $file, string $data, [ string $writeOption = 'a' ] )

$fileをfopen()のモード$writeOptionで開いて$dataを書き込み、ファイルのパーミッションを0644(誰でも読める)にします。デフォルトのモードaはファイルに追記します。上書きするときはwを使います。

ファイルを開けない場合や、書き込めない場合はfalseを返します。

引数​

名前データ型デフォルト備考
$filestring書き込むファイル
$datastring書き込むデータ
$writeOptionstring'a'fopen()のモード(a:追記、w:上書き)

例​

Controller
use Fegg\Tool\File;

$file = new File();

// Append a line
$file->writeFile('path/to/foo.log', date('Y-m-d H:i:s') . " done\n");

// Overwrite the file
if (!$file->writeFile('path/to/foo.txt', 'New contents', 'w')) {
// could not be written
}