E
E
Evgeny Kylin2016-10-14 15:49:03
PHP
Evgeny Kylin, 2016-10-14 15:49:03

How to display pictures from Yandex Disk?

How to display pictures from Yandex Disk using PHP on the site?
first i get all links

require_once 'phar://yandex-php-library_master.phar/vendor/autoload.php';
  $ydwork_token = get_option('ydwork_token');
  $diskClient = new DiskClient($ydwork_token);
  $dirContent = $diskClient->directoryContents(urlencode('/'));

then I iterate over them and get the objects
foreach($dirContent as $file){
    if($file['contentType'] == 'image/jpeg'){
      $files[] = $diskClient->getImagePreview($file['href'], '200x200');
    }elseif($file['contentType'] == ''){
      $dir[] = $file['href'];
    }
}
var_dump($files);

["headers"]=>
  array(7) {
    ["yandex-cloud-request-id"]=>
    string(27) "dav-PSK6_694_9I2-2-webdav4j"
    ["server"]=>
    string(12) "MochiWeb/1.0"
    ["keep-alive"]=>
    string(11) "timeout=300"
    ["date"]=>
    string(29) "Fri, 14 Oct 2016 12:52:50 GMT"
    ["content-type"]=>
    string(10) "image/jpeg"
    ["content-length"]=>
    string(5) "14115"
    ["accept-ranges"]=>
    string(5) "bytes"
  }
  ["body"]=>
  object(GuzzleHttp\Psr7\Stream)#3235 (7) {
    ["stream":"GuzzleHttp\Psr7\Stream":private]=>
    resource(335) of type (stream)
    ["size":"GuzzleHttp\Psr7\Stream":private]=>
    NULL
    ["seekable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["readable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["writable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["uri":"GuzzleHttp\Psr7\Stream":private]=>
    string(10) "php://temp"
    ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
    array(0) {
    }
  }

What to do next with these objects? How can I insert them into the body of the page?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question