Display Google Drive into elFinder using flysystem










0















I want to create a google drive flysystem.
I create this app based Yii2, but I dont mind if you give me another solution in php.



Ok, so far, this what I've done.




  1. composer require creocoder/yii2-flysystem for the Flysystem


  2. composer require nao-pon/flysystem-google-drive:~1.1 for the Adapter

I create a configuration in config/web.php



'components' => [
'googleDrive' => [
'class' => 'appmodulessuperAdmincomponentsGoogleDriveFilesystem',
'clientId' => 'myIDHere',
'clientSecret' => 'secretHere',
'refreshToken' => 'tokenHere',
'rootFolderId' => ''
],
]


then this is the GoogleDriveFilesystem that I extends from creocoderflysystemFilesystem;



namespace appmodulessuperAdmincomponents;


use creocoderflysystemFilesystem;
use elFinder;
use elFinderConnector;
use Google_Client;
use Google_Service_Drive;
use HypwebFlysystemGoogleDriveGoogleDriveAdapter;
use yiibaseInvalidConfigException;

class GoogleDriveFilesystem extends Filesystem

public $clientId;
public $clientSecret;
public $refreshToken;
public $rootFolderId;
public $adapter;

/**
* @inheritdoc
*/
public function init()

if ($this->clientId === null)
throw new InvalidConfigException('The "clientId" property must be set.');

if ($this->clientSecret === null)
throw new InvalidConfigException('The "clientSecret" property must be set.');

if ($this->refreshToken === null)
throw new InvalidConfigException('The "refreshToken" property must be set.');

parent::init();


/**
* @return GoogleDriveAdapter
*/
protected function prepareAdapter()

$client = new Google_Client();
$client->setClientId($this->clientId);
$client->setClientSecret($this->clientSecret);
$client->refreshToken($this->refreshToken);
$service = new Google_Service_Drive($client);

$this->adapter = new GoogleDriveAdapter($service, $this->rootFolderId, [
'useHasDir' => true
]);
return $this->adapter;



public function displayInElFinder()

$googleDrive = $this->adapter;
// Make Flysystem adapter and cache object
$useCache = true;
if ($useCache)
// Example to Flysystem cacheing
$cache = new LeagueFlysystemCachedStorageAdapter(
new LeagueFlysystemAdapterLocal('flycache'),
'gdcache',
300
);

// Flysystem cached adapter
$adapter = new LeagueFlysystemCachedCachedAdapter(
$googleDrive,
$cache
);
else
// Not use cached adapter
$cache = null;
$adapter = $googleDrive;


// Google Drive elFinder Volume driver
$gdrive = [
// require
'driver' => 'FlysystemExt',
'filesystem' => new LeagueFlysystemFilesystem($adapter),
'fscache' => $cache,
'separator' => '/',
'alias' => 'GoogleDrive',
'rootCssClass' => 'elfinder-navbar-root-googledrive'
];

// elFinder volume roots options
$elFinderOpts = [
'roots' =>
];

$elFinderOpts['roots'] = $gdrive;

// run elFinder
$connector = new elFinderConnector(new elFinder($elFinderOpts));
$connector->run();;




For the testing, I use



<?php $obj = Yii::$app->googleDrive;?>

<pre>
<?= yiihelperVarDumper::dumpAsString($obj->listContents()) ?>
</pre>


I got success one.



[
0 => [
'name' => 'Contoh BL'
'type' => 'dir'
'path' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
'filename' => 'Contoh BL'
'extension' => ''
'timestamp' => 1542228118
'size' => 0
'hasdir' => false
'dirname' => ''
'basename' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
]
]


But how to display them into elFinder,
I try like this,



<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<?php $obj = Yii::$app->googleDrive; ?>

<?php $obj->displayInElFinder() ?>
</div>
</div>


I got error like this:




"error": [
"errUnknownCmd"
]










share|improve this question


























    0















    I want to create a google drive flysystem.
    I create this app based Yii2, but I dont mind if you give me another solution in php.



    Ok, so far, this what I've done.




    1. composer require creocoder/yii2-flysystem for the Flysystem


    2. composer require nao-pon/flysystem-google-drive:~1.1 for the Adapter

    I create a configuration in config/web.php



    'components' => [
    'googleDrive' => [
    'class' => 'appmodulessuperAdmincomponentsGoogleDriveFilesystem',
    'clientId' => 'myIDHere',
    'clientSecret' => 'secretHere',
    'refreshToken' => 'tokenHere',
    'rootFolderId' => ''
    ],
    ]


    then this is the GoogleDriveFilesystem that I extends from creocoderflysystemFilesystem;



    namespace appmodulessuperAdmincomponents;


    use creocoderflysystemFilesystem;
    use elFinder;
    use elFinderConnector;
    use Google_Client;
    use Google_Service_Drive;
    use HypwebFlysystemGoogleDriveGoogleDriveAdapter;
    use yiibaseInvalidConfigException;

    class GoogleDriveFilesystem extends Filesystem

    public $clientId;
    public $clientSecret;
    public $refreshToken;
    public $rootFolderId;
    public $adapter;

    /**
    * @inheritdoc
    */
    public function init()

    if ($this->clientId === null)
    throw new InvalidConfigException('The "clientId" property must be set.');

    if ($this->clientSecret === null)
    throw new InvalidConfigException('The "clientSecret" property must be set.');

    if ($this->refreshToken === null)
    throw new InvalidConfigException('The "refreshToken" property must be set.');

    parent::init();


    /**
    * @return GoogleDriveAdapter
    */
    protected function prepareAdapter()

    $client = new Google_Client();
    $client->setClientId($this->clientId);
    $client->setClientSecret($this->clientSecret);
    $client->refreshToken($this->refreshToken);
    $service = new Google_Service_Drive($client);

    $this->adapter = new GoogleDriveAdapter($service, $this->rootFolderId, [
    'useHasDir' => true
    ]);
    return $this->adapter;



    public function displayInElFinder()

    $googleDrive = $this->adapter;
    // Make Flysystem adapter and cache object
    $useCache = true;
    if ($useCache)
    // Example to Flysystem cacheing
    $cache = new LeagueFlysystemCachedStorageAdapter(
    new LeagueFlysystemAdapterLocal('flycache'),
    'gdcache',
    300
    );

    // Flysystem cached adapter
    $adapter = new LeagueFlysystemCachedCachedAdapter(
    $googleDrive,
    $cache
    );
    else
    // Not use cached adapter
    $cache = null;
    $adapter = $googleDrive;


    // Google Drive elFinder Volume driver
    $gdrive = [
    // require
    'driver' => 'FlysystemExt',
    'filesystem' => new LeagueFlysystemFilesystem($adapter),
    'fscache' => $cache,
    'separator' => '/',
    'alias' => 'GoogleDrive',
    'rootCssClass' => 'elfinder-navbar-root-googledrive'
    ];

    // elFinder volume roots options
    $elFinderOpts = [
    'roots' =>
    ];

    $elFinderOpts['roots'] = $gdrive;

    // run elFinder
    $connector = new elFinderConnector(new elFinder($elFinderOpts));
    $connector->run();;




    For the testing, I use



    <?php $obj = Yii::$app->googleDrive;?>

    <pre>
    <?= yiihelperVarDumper::dumpAsString($obj->listContents()) ?>
    </pre>


    I got success one.



    [
    0 => [
    'name' => 'Contoh BL'
    'type' => 'dir'
    'path' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
    'filename' => 'Contoh BL'
    'extension' => ''
    'timestamp' => 1542228118
    'size' => 0
    'hasdir' => false
    'dirname' => ''
    'basename' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
    ]
    ]


    But how to display them into elFinder,
    I try like this,



    <div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <?php $obj = Yii::$app->googleDrive; ?>

    <?php $obj->displayInElFinder() ?>
    </div>
    </div>


    I got error like this:




    "error": [
    "errUnknownCmd"
    ]










    share|improve this question
























      0












      0








      0








      I want to create a google drive flysystem.
      I create this app based Yii2, but I dont mind if you give me another solution in php.



      Ok, so far, this what I've done.




      1. composer require creocoder/yii2-flysystem for the Flysystem


      2. composer require nao-pon/flysystem-google-drive:~1.1 for the Adapter

      I create a configuration in config/web.php



      'components' => [
      'googleDrive' => [
      'class' => 'appmodulessuperAdmincomponentsGoogleDriveFilesystem',
      'clientId' => 'myIDHere',
      'clientSecret' => 'secretHere',
      'refreshToken' => 'tokenHere',
      'rootFolderId' => ''
      ],
      ]


      then this is the GoogleDriveFilesystem that I extends from creocoderflysystemFilesystem;



      namespace appmodulessuperAdmincomponents;


      use creocoderflysystemFilesystem;
      use elFinder;
      use elFinderConnector;
      use Google_Client;
      use Google_Service_Drive;
      use HypwebFlysystemGoogleDriveGoogleDriveAdapter;
      use yiibaseInvalidConfigException;

      class GoogleDriveFilesystem extends Filesystem

      public $clientId;
      public $clientSecret;
      public $refreshToken;
      public $rootFolderId;
      public $adapter;

      /**
      * @inheritdoc
      */
      public function init()

      if ($this->clientId === null)
      throw new InvalidConfigException('The "clientId" property must be set.');

      if ($this->clientSecret === null)
      throw new InvalidConfigException('The "clientSecret" property must be set.');

      if ($this->refreshToken === null)
      throw new InvalidConfigException('The "refreshToken" property must be set.');

      parent::init();


      /**
      * @return GoogleDriveAdapter
      */
      protected function prepareAdapter()

      $client = new Google_Client();
      $client->setClientId($this->clientId);
      $client->setClientSecret($this->clientSecret);
      $client->refreshToken($this->refreshToken);
      $service = new Google_Service_Drive($client);

      $this->adapter = new GoogleDriveAdapter($service, $this->rootFolderId, [
      'useHasDir' => true
      ]);
      return $this->adapter;



      public function displayInElFinder()

      $googleDrive = $this->adapter;
      // Make Flysystem adapter and cache object
      $useCache = true;
      if ($useCache)
      // Example to Flysystem cacheing
      $cache = new LeagueFlysystemCachedStorageAdapter(
      new LeagueFlysystemAdapterLocal('flycache'),
      'gdcache',
      300
      );

      // Flysystem cached adapter
      $adapter = new LeagueFlysystemCachedCachedAdapter(
      $googleDrive,
      $cache
      );
      else
      // Not use cached adapter
      $cache = null;
      $adapter = $googleDrive;


      // Google Drive elFinder Volume driver
      $gdrive = [
      // require
      'driver' => 'FlysystemExt',
      'filesystem' => new LeagueFlysystemFilesystem($adapter),
      'fscache' => $cache,
      'separator' => '/',
      'alias' => 'GoogleDrive',
      'rootCssClass' => 'elfinder-navbar-root-googledrive'
      ];

      // elFinder volume roots options
      $elFinderOpts = [
      'roots' =>
      ];

      $elFinderOpts['roots'] = $gdrive;

      // run elFinder
      $connector = new elFinderConnector(new elFinder($elFinderOpts));
      $connector->run();;




      For the testing, I use



      <?php $obj = Yii::$app->googleDrive;?>

      <pre>
      <?= yiihelperVarDumper::dumpAsString($obj->listContents()) ?>
      </pre>


      I got success one.



      [
      0 => [
      'name' => 'Contoh BL'
      'type' => 'dir'
      'path' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
      'filename' => 'Contoh BL'
      'extension' => ''
      'timestamp' => 1542228118
      'size' => 0
      'hasdir' => false
      'dirname' => ''
      'basename' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
      ]
      ]


      But how to display them into elFinder,
      I try like this,



      <div class="row">
      <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
      <?php $obj = Yii::$app->googleDrive; ?>

      <?php $obj->displayInElFinder() ?>
      </div>
      </div>


      I got error like this:




      "error": [
      "errUnknownCmd"
      ]










      share|improve this question














      I want to create a google drive flysystem.
      I create this app based Yii2, but I dont mind if you give me another solution in php.



      Ok, so far, this what I've done.




      1. composer require creocoder/yii2-flysystem for the Flysystem


      2. composer require nao-pon/flysystem-google-drive:~1.1 for the Adapter

      I create a configuration in config/web.php



      'components' => [
      'googleDrive' => [
      'class' => 'appmodulessuperAdmincomponentsGoogleDriveFilesystem',
      'clientId' => 'myIDHere',
      'clientSecret' => 'secretHere',
      'refreshToken' => 'tokenHere',
      'rootFolderId' => ''
      ],
      ]


      then this is the GoogleDriveFilesystem that I extends from creocoderflysystemFilesystem;



      namespace appmodulessuperAdmincomponents;


      use creocoderflysystemFilesystem;
      use elFinder;
      use elFinderConnector;
      use Google_Client;
      use Google_Service_Drive;
      use HypwebFlysystemGoogleDriveGoogleDriveAdapter;
      use yiibaseInvalidConfigException;

      class GoogleDriveFilesystem extends Filesystem

      public $clientId;
      public $clientSecret;
      public $refreshToken;
      public $rootFolderId;
      public $adapter;

      /**
      * @inheritdoc
      */
      public function init()

      if ($this->clientId === null)
      throw new InvalidConfigException('The "clientId" property must be set.');

      if ($this->clientSecret === null)
      throw new InvalidConfigException('The "clientSecret" property must be set.');

      if ($this->refreshToken === null)
      throw new InvalidConfigException('The "refreshToken" property must be set.');

      parent::init();


      /**
      * @return GoogleDriveAdapter
      */
      protected function prepareAdapter()

      $client = new Google_Client();
      $client->setClientId($this->clientId);
      $client->setClientSecret($this->clientSecret);
      $client->refreshToken($this->refreshToken);
      $service = new Google_Service_Drive($client);

      $this->adapter = new GoogleDriveAdapter($service, $this->rootFolderId, [
      'useHasDir' => true
      ]);
      return $this->adapter;



      public function displayInElFinder()

      $googleDrive = $this->adapter;
      // Make Flysystem adapter and cache object
      $useCache = true;
      if ($useCache)
      // Example to Flysystem cacheing
      $cache = new LeagueFlysystemCachedStorageAdapter(
      new LeagueFlysystemAdapterLocal('flycache'),
      'gdcache',
      300
      );

      // Flysystem cached adapter
      $adapter = new LeagueFlysystemCachedCachedAdapter(
      $googleDrive,
      $cache
      );
      else
      // Not use cached adapter
      $cache = null;
      $adapter = $googleDrive;


      // Google Drive elFinder Volume driver
      $gdrive = [
      // require
      'driver' => 'FlysystemExt',
      'filesystem' => new LeagueFlysystemFilesystem($adapter),
      'fscache' => $cache,
      'separator' => '/',
      'alias' => 'GoogleDrive',
      'rootCssClass' => 'elfinder-navbar-root-googledrive'
      ];

      // elFinder volume roots options
      $elFinderOpts = [
      'roots' =>
      ];

      $elFinderOpts['roots'] = $gdrive;

      // run elFinder
      $connector = new elFinderConnector(new elFinder($elFinderOpts));
      $connector->run();;




      For the testing, I use



      <?php $obj = Yii::$app->googleDrive;?>

      <pre>
      <?= yiihelperVarDumper::dumpAsString($obj->listContents()) ?>
      </pre>


      I got success one.



      [
      0 => [
      'name' => 'Contoh BL'
      'type' => 'dir'
      'path' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
      'filename' => 'Contoh BL'
      'extension' => ''
      'timestamp' => 1542228118
      'size' => 0
      'hasdir' => false
      'dirname' => ''
      'basename' => '1oF2A4SVTGL3zq9XDRF7o2hIzZ66IFeFS'
      ]
      ]


      But how to display them into elFinder,
      I try like this,



      <div class="row">
      <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
      <?php $obj = Yii::$app->googleDrive; ?>

      <?php $obj->displayInElFinder() ?>
      </div>
      </div>


      I got error like this:




      "error": [
      "errUnknownCmd"
      ]







      php yii2 elfinder flysystem-google-drive






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 5:26









      Fadly DzilFadly Dzil

      8381540




      8381540






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312961%2fdisplay-google-drive-into-elfinder-using-flysystem%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312961%2fdisplay-google-drive-into-elfinder-using-flysystem%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo