|
|
- <?php
-
- namespace CustomHandlers\Actions;
-
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Str;
-
- use Mimey\MimeTypes;
-
- /**
- *
- *
- *
- */
-
- class FileDownload extends ActionHandler
- {
- public function run()
- {
- if (isset($this->data->enclosure) && isset($this->data->enclosure->attributes()->url)) {
-
- // get mimes
- $mimes = new MimeTypes();
- $extension = $mimes->getExtension($this->data->enclosure->attributes()->type);
-
- // if extension valid
- if ($extension) {
- $filename = Str::slug($this->data->title).'.'.$extension;
- Storage::download($this->data->enclosure->attributes()->url)->put($filename);
- } else {
- // @TODO what you do
- }
- }
- }
- }
|