PHP code example of supham / yii2-flysystem

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

    

supham / yii2-flysystem example snippets


$config['components']['fs'] = [
            '__class' => 'Supham\Flysystem\Filesystem',
            'plugins' => ['Supham\Flysystem\Plugin\PublicUrl'],
            'defaultAdapter' => 'cloud',
            'mounts' => [
              'tmp' => [
                '__class' => 'Supham\Flysystem\Adapter\Local',
                'args' => [ini_get('upload_tmp_dir') ?: sys_get_temp_dir()],
              ],
              'alfresco' => [
                '__class' => 'Supham\Flysystem\Adapter\Alfresco',
                'pathPrefix' => '-my-', // pilih satu [-root-, -my-, -shared-]
                'apiUrl' => 'http://127.0.0.1:8080/alfresco/api/',
                'username' => 'username',
                'password' => 'password',
              ],
              'aliyun-oss' => [
                '__class' => 'Supham\Flysystem\Adapter\AliyunOss',
                'args'=>[[
                  'bucket'         => aliyun_oss_bucket_name,
                  'endpoint'       => aliyun_oss_endpoint_address,
                  'accessId'       => aliyun_access_id,
                  'accessSecret'   => aliyun_access_secret,
                  // 'timeout'        => 3600,
                  // 'connectTimeout' => 10,
                  // 'isCName'        => false,
                  // 'token'          => '',
                ]],
              ],
            ],
],

      // Download file dari cloud
      $stream = Yii::$app->fs->readStream('path/to/file.txt');
      return Yii::$app->response->sendStreamAsFile($stream, 'downloaded-file.txt');

      // Upload content string
      $content = file_get_contents('/home/xubuncup/Documents/Akademi_VSGA_flyer.pdf');
      $a = Yii::$app->fs->write('arsip/filex.txt', $content);

      // Upload stream resource
      $stream = fopen('/home/xubuncup/Documents/Akademi_VSGA_flyer.pdf', 'r');
      $a = Yii::$app->fs->write('arsip/filex.txt', $stream);


      // Copy dari local /tmp ke alfresco
      Yii::$app->fs->copy("tmp:{$file->tempName}", "alfresco:$filePath", $config);

      // createDir
      $b = Yii::$app->fs->createDir('create_foldir_via_flysystem');