Skip to content

Instantly share code, notes, and snippets.

@KhunHtetzNaing
Created June 16, 2020 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KhunHtetzNaing/23da3515fbb9e5add6c3370d439fa7cf to your computer and use it in GitHub Desktop.
Save KhunHtetzNaing/23da3515fbb9e5add6c3370d439fa7cf to your computer and use it in GitHub Desktop.
Yadisk API
<?php
$yadisk = 'https://yadi.sk/i/d-8trVHpcT6qQA';
$json = file_get_contents("https://cloud-api.yandex.net/v1/disk/public/resources/?public_key={$yadisk}");
$json = json_decode($json);
echo 'File => ' . $json->file . 'Size => ' . sizeFilter($json->size) . 'Name => ' . $json->name;
function sizeFilter($bytes)
{
$label = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
for ($i = 0; $bytes >= 1024 && $i < (count($label) - 1); $bytes /= 1024, $i++);
return (round($bytes, 2) . " " . $label[$i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment