BenExile / Dropbox

UNMAINTAINED: PHP 5.3 SDK for the Dropbox REST API
MIT License
521 stars 134 forks source link

How can I get the size of a folder #61

Closed vanderwijk closed 11 years ago

vanderwijk commented 11 years ago

I am trying to find out how to display the total size of a specific folder. When I do $dropbox->metaData('Folder Name') the result always shows [bytes] => 0 and [size] => 0 bytes even when there are files inside the folder.

Is there a way to get the folder size or is this a bug with Dropbox?

vanderwijk commented 11 years ago

For future reference; I Came up with this code which adds up the sizes of all the files inside a folder to find out the size of the folder:

function mx_check_dropbox_size( $folder ) { global $dropbox; $foldersize = 0; $foldercontents = $dropbox -> metaData( $folder ); foreach( $foldercontents["body"] -> contents as $file ) { $foldersize += $file -> size; } if ( $foldersize == 0 ) echo '✘'; if ( $foldersize >= 20 ) echo '✔'; };

mx_check_dropbox_size( "Test/Folder" );

(The check for the foldersize and echo of the checkmark or cross is something I need for my app so you can ignore that)

The page that needs this code is going to call the mx_check_dropbox_size function about a hundred times, so I might run into some performance issues. This is why I would much rather get the folder size from the array that Dropbox is sending.

BenExile commented 11 years ago

Dropbox will always return 0 bytes for a directory as described here. It's a shame because to get the size of a folder, including files and folders within, you have to make several API calls. You could contact Dropbox regarding this issue but it is not something I can address, unfortunately.

vanderwijk commented 11 years ago

Hi Ben, thanks for your reply. I have contacted Dropbox about this and their response was that my feedback would be passed on. Not sure if this means that they will actually do something about it :)