I am trying to list all files in a specific Dropbox folder, including the files in subfolders, but without displaying the folders themselves.
I am using the DropboxClient PHP Class, but am not attached to it.
My current code works only for files in the first subfolders. Plus it takes a very long time to load due to me querying Dropbox about each folder's content independently. I know I could get a one-time recursive API call, but I seem to fail at working with the Array.
<?php
$folders = $dropbox->GetFiles("/Downloads/",false);
if(!empty($folders)) {
$i=0;
foreach($folders as $o) {
if ($o->is_dir = true) {
list(, $foldername) = explode('-', $o->path, 2);
$i++;
$cat[$i] = $foldername;
echo '<h2>'.$foldername.'</h2>';
$files = $dropbox->GetFiles($o->path,false);
?>
<table>
<tbody><tr>
<th>File</th>
<th>Date</th>
<th>Title</th>
<th>Description</th>
</tr>
<?php foreach($files as $f): ?>
<?php
$filelink = $dropbox->GetLink($f, false);
$filetype = pathinfo($f->path, PATHINFO_EXTENSION);
$filename = pathinfo($f->path, PATHINFO_FILENAME);
$filenamesplit = explode ( '_-_', $filename);
?>
<tr>
<td><a href="<?= $filelink ?>" target="_blank">Download</a></td>
<td><?= date("d.m.Y", strtotime($f->modified)); ?></td>
<td><?= $filenamesplit[0] ?></td>
<td><?= $filenamesplit[1] ?></td>
</tr>
<?php endforeach; ?>
</tbody></table>
<?php
}
}
}
The file structure is e.g. something like this:
Cat1Folder - File 1
Cat1Folder - SubFolder - File 2
Cat1Folder - SubFolder - File 3
Cat2Folder - File 1
Cat2Folder - SubFolder - File 2
And I want a pure list of files to be outputted, regardless of the folder they're in.
Cat1Folder:
File 1
File 2
File 3
Cat2Folder:
File 1
File 2
I think you're not longer interested, but while I was looking for something similar I found this from you. From "DropboxClient PHP Class" documentation :
So I think you just change your code to:
$dropbox->GetFiles("/Downloads/",true);