1. Go to this page and download the library: Download incapption/file-system library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
incapption / file-system example snippets
class MyFile extends Incapption\FileSystem\File
{
/**
* @param string|null $filePath
*/
public function __construct(?string $filePath = null)
{
$adapter = new LocalFilesystemAdapter(
'path/to/root' # Path to the root of you application
);
parent::__construct($adapter, $filePath);
}
public function myCustomMethod()
{
// you can extend your own class with additional methods
}
}
// examples
$file = new MyFile('public/images/avatar03.jpg');
$file->__delete();
$file = new MyFile();
$file->__write('user/1/101/images/avatar.jpg', file_get_contents('tmp/uploaded_avatar.jpg'));
class MyS3File extends Incapption\FileSystem\File
{
/**
* @param string|null $filePath
*/
public function __construct(?string $filePath = null)
{
$client = new S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'endpoint' => 'https://s3.us-east-2.amazonaws.com',
'credentials' => [
'key' => 'YOUR_API_KEY',
'secret' => 'YOUR_API_SECRET',
],
'http' => [
'timeout' => 10,
'connect_timeout' => 10,
],
]);
$adapter = new League\Flysystem\AwsS3V3\AwsS3V3Adapter(
$client,
'your-bucket-name'
);
parent::__construct($adapter, $filePath);
}
public function myCustomMethod()
{
// you can extend your own class with additional methods
}
}
// examples
$file = new MyFile('public/images/avatar03.jpg');
$file->__delete();
$file = new MyFile();
$file->__write('user/1/101/images/avatar.jpg', file_get_contents('tmp/uploaded_avatar.jpg'));
public function __construct(FilesystemAdapter $adapter, ?string $filePath = null);
public function __write(string $dest, $contents): FileInterface;
public function __writeStream(string $dest, $contents): FileInterface;
public function __move(string $dest): FileInterface;
public function __rename(string $new_name): FileInterface;
public function __copy(string $dest): FileInterface;
public function __delete(): bool;
public function getContent(): string;
public function getFullPath(): string;
public function getName(): string;
public function getSize(): int;
public function getExtension(): string;
public function getMimeType(): string;
public function getLastModified(): int;
public function getDirectoryName(): string;
public function toArray(): array;
public function toJson(): string;
/* IN ADDITION:
* all public function from \League\Flysystem\Filesystem
*/
bash
PHP >= 7.2
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.