DLight\Application\File
Mô tả: storage đơn giản hỗ trợ 2 driver: local và ftp.
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): booldelete(string $path): boolurl(string $path): string(trả ra fullPath theo root)read(string $path): stringwrite(string $path, string $content): boolappend(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');