1. Go to this page and download the library: Download reshadman/file-secretary 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/ */
reshadman / file-secretary example snippets
return [
// other app.php config elements
'providers' => [
// Other providers
// ...
\Reshadman\FileSecretary\Infrastructure\FileSecretaryServiceProvider::class
]
];
return [
// Other file secretary config elements...
'contexts' => [
// Other contexts...
'assets_context' => [
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_ASSET,
'driver' => 'rackspace_asset_disk',
'context_folder' => 'some_context_folder',
'driver_base_address' => 'some-unique-string.rackcdn.com/etc/',
]
],
'asset_folders' => [
'backoffice' => [
'path' => public_path('backoffice-assets'),
'context' => 'assets_context',
// fills .env automatically like => BACKOFFICE_ASSET_ID=unique-id
// which causes to the browser to not serve old versions.
'env_key' => 'BACKOFFICE_ASSET_ID',
],
]
];
$url = fs_asset('backoffice', 'styles.dist.css');
dump($url);
// In development env: http://localhost:8000/backoffice/styles.dist.css
// In production env: some-unique-id.rackcdn.com/[context_folder]/[latest-unique-id]/styles.dist.css
return [
// Other config file_secretary config elements
'listeners' => [
\Reshadman\FileSecretary\Application\Events\AfterAssetUpload::class => [
'\YourListener\Class',
]
],
];
$presentedFile = new \Reshadman\FileSecretary\Application\PresentedFile(
'file_manager_private', // context name
'SOME_TEXT_CONTENT_HERE_', // The mime type will be detected automatically.
\Reshadman\FileSecretary\Application\PresentedFile::FILE_TYPE_CONTENT
);
/** @var \Reshadman\FileSecretary\Application\Usecases\StoreFile $storeCommand */
$storeCommand = app(\Reshadman\FileSecretary\Application\Usecases\StoreFile::class);
$addressableRemoteFile = $storeCommand->execute($presentedFile);
dd($addressableRemoteFile->fullRelative(), $addressableRemoteFile->fullUrl());
$presentedFile = new \Reshadman\FileSecretary\Application\PresentedFile(
'file_manager_private', // context name
$path = '../path_to/my_file.png',
\Reshadman\FileSecretary\Application\PresentedFile::FILE_TYPE_PATH,
basename($path)
);
$presentedFile = new \Reshadman\FileSecretary\Application\PresentedFile(
'file_manager_private', // context name
file_get_contents($path = '../path_to/my_file.png'), // The mime type will be detected automatically.
\Reshadman\FileSecretary\Application\PresentedFile::FILE_TYPE_CONTENT
);
$presentedFile = new \Reshadman\FileSecretary\Application\PresentedFile(
'file_manager_private', // context name
request()->file('company_logo'), // The mime type will be detected automatically.
\Reshadman\FileSecretary\Application\PresentedFile::FILE_TYPE_INSTANCE
);
$presentedFile = new \Reshadman\FileSecretary\Application\PresentedFile(
'file_manager_private', // context name
'https://logo_url.com/logo.png', // The mime type will be detected automatically.
\Reshadman\FileSecretary\Application\PresentedFile::FILE_TYPE_URL
);
$presentedFile = new \Reshadman\FileSecretary\Application\PresentedFile(
'file_manager_private', // context name
'base64encodecontent=', // The mime type will be detected automatically.
\Reshadman\FileSecretary\Application\PresentedFile::FILE_TYPE_BASE64
);
$presentedFile = new \Reshadman\FileSecretary\Application\PresentedFile(
'user_images_context',
request()->file('avatar_file'),
\Reshadman\FileSecretary\Application\PresentedFile::FILE_TYPE_INSTANCE,
basename(request()->file('avatar_file')) // Is stored in the table so you can show the client's name if needed.
);
/** @var \Reshadman\FileSecretary\Application\Usecases\StoreTrackedFile $storeTrackedFile */
$storeTrackedFile = app(\Reshadman\FileSecretary\Application\Usecases\StoreTrackedFile::class);
$trackedModel = $storeTrackedFile->execute($presentedFile);
auth()->user()->avatar()->attach($trackedModel);
dump($trackedModel->full_url);
echo "<img src='{$trackedModel->image_templates['avatar_50x50']}' title='{$trackedModel->original_name}'/>";