1. Go to this page and download the library: Download anomaly/file-field-type 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/ */
$entry = $model->find(1);
// Get file object
$file = $entry->attachment;
if ($file) {
// Get file properties
$name = $file->name;
$path = $file->path();
$size = $file->size;
$extension = $file->extension;
$mimeType = $file->mime_type;
// Get file ID
$fileId = $entry->attachment_id;
// Image manipulation
if ($file->isImage()) {
$thumbnail = $file->make()->fit(150, 150)->path();
}
}
$form = $builder->make('example.module.test');
$form->on('saving', function(FormBuilder $builder) {
$entry = $builder->getFormEntry();
// Set file ID
$entry->attachment = 5;
});
// Set by file ID
$entry->attachment_id = 10;
$entry->save();
// Or set by file object
$file = File::find(10);
$entry->attachment()->associate($file);
$entry->save();