PHP code example of insolita / yii2-multifs

1. Go to this page and download the library: Download insolita/yii2-multifs 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/ */

    

insolita / yii2-multifs example snippets


 $avatars = (new \insolita\multifs\builders\LocalFsBuilder('@app/web/uploads/avatars'))->build();
 $covers = (new \insolita\multifs\builders\LocalFsBuilder('@app/web/uploads/covers'))->build();
 $attach = (new \insolita\multifs\builders\LocalFsBuilder('@app/web/uploads/attach'))->build();
 $data = (new \insolita\multifs\builders\LocalFsBuilder('@data'))->build();

 \insolita\multifs\contracts\IMultifsManager::class                                              => [
                \insolita\multifs\MultiFsManager::class,
                [
                    [
                        'avatars'  => $avatars,
                        'covers'   => $covers,
                        'attach'   => $attach,
                        'internal' => $data,
                    ],
                ],
            ],
            \insolita\multifs\contracts\IUploader::class=>[
                \insolita\multifs\Uploader::class,
                [
                    \yii\di\Instance::of(\insolita\multifs\contracts\IMultifsManager::class),
                    'attach'
                ]
            ],



'components'=>[
   'multifs'=>\insolita\multifs\contracts\IMultifsManager::class,
   'uploader'=>\insolita\multifs\contracts\IUploader::class,
]
 


      echo Yii::$app->multifs->listPrefixes();
      Yii::$app->multifs->mountFilesystem('special', new Filesystem(new Adapter(...)));
      Yii::$app->multifs->write('special://some/file/path/name.txt','Hello Test');
      $fs = Yii::$app->multifs->getFilesystem('internal');
      Vardumper::dump($fs->listConents('',true));

  


     $file = \yii\web\UploadedFile::getInstanceByName('file');
     $path = Yii::$app->uploader->setFsPrefix('avatars')
               ->setFileNameStrategy(new insolita\multifs\strategy\filename\AsIsStrategy())
               ->setFilePathStrategy(new insolita\multifs\strategy\filename\NameHashStrategy())
               ->setFileSaveStrategy(new insolita\multifs\strategy\filename\ExceptionSaveExistsStrategy())
               ->save($file);

    \Yii::$app->response->sendStreamAsFile(Yii::$app->multifs->readStream($path),
                                            pathinfo($path, PATHINFO_BASENAME),
                                            [
                                               'mimeType' => $file->getType(),
                                               'inline'=>true
                                            ]);