File::writeFile
ファイルにデータを書き込みます
説明
public bool File::writeFile( string $file, string $data, [ string $writeOption = 'a' ] )
$fileをfopen()のモード$writeOptionで開いて$dataを書き込み、ファイルのパーミッションを0644(誰でも読める)にします。デフォルトのモードaはファイルに追記します。上書きするときはwを使います。
ファイルを開けない場合や、書き込めない場合はfalseを返します。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $file | string | 書き込むファイル | |
| $data | string | 書き込むデータ | |
| $writeOption | string | '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
}