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

はじめに

ファイルとディレクトリの操作

使用方法​

Fegg\Tool\Fileをインポートし、newで作成します。

Controller
<?php
namespace Site\Controller;

defined('FEGG_CORE_DIR') || exit;

use Fegg\Tool\File;

class Export extends Controller
{
public function index()
{
$file = new File();

if (!$file->createDirectory(FEGG_SITE_DIR . '/data/export')
|| !$file->writeFile(FEGG_SITE_DIR . '/data/export/list.csv', "id,title\n", 'w')) {
throw new \RuntimeException('The export could not be written');
}
}
}
メモ

どのメソッドも、処理ができたらtrueを、できなかったら(コピー元がない、ファイルに書き込めない、ディレクトリを読み込めないなど)falseを返します。File::readFileだけは内容を返し、ファイルを読み込めなければ''を返します。

ディレクトリの削除・コピー・更新日時の変更では、シンボリックリンクをたどりません。リンク自体を削除する(または飛ばす)だけで、リンク先には触れません。

関数​