Laravel檔案系統,自定義日誌檔案、管理檔案--Star.hou
阿新 • • 發佈:2018-12-10
使用local驅動的時候,注意所有檔案操作相對於定義在配置檔案中的root目錄,預設情況下,該值設定為storage/app目錄,因此,下面的方法將會儲存檔案到storage/app/file.txt:
Storage::disk('local')->put('file.txt', 'Contents');
如果要修改storage/app/file.txt路徑未非專案路徑,需要修改驅動配置: config/filesystem.php下面
'local' => [ 'driver' => 'local', 'root' => storage_path('app'), //修改 'root' => '/abc/dddd', ],
新增內容到檔案開頭/結尾 prepend和append方法允許你輕鬆插入內容到檔案開頭/結尾:
Storage::prepend('file.log', 'Prepended Text');
Storage::append('file.log', 'Appended Text');