DLight\Application\File

Mô tả: storage đơn giản hỗ trợ 2 driver: localftp. Root path lấy từ config, mọi thao tác đều tính theo root.

Namespace / đăng ký

  • Namespace: DLight\Application
  • File: src/Application/File.php

Public API

  • __construct(array $config)
  • exists(string $path): bool
  • delete(string $path): bool
  • url(string $path): string (trả ra fullPath theo root)
  • read(string $path): string
  • write(string $path, string $content): bool
  • append(string $path, string $content): bool

Demo local driver

use DLight\Application\File;

$fs = new File([
  'driver' => 'local',
  'root'   => INDEX_DIR . 'storage',
]);

$fs->write('notes/hello.txt', "Hello\n");
echo $fs->read('notes/hello.txt');

Demo FTP driver

use DLight\Application\File;

$ftp = new File([
  'driver' => 'ftp',
  'root'   => '/public_html',
  'host'   => 'ftp.example.com',
  'port'   => 21,
  'username' => 'user',
  'password' => 'pass',
  'passive'  => true,
]);

$ftp->write('uploads/a.txt', 'data');