Secure Bucket Assets

  • Hi,

    Anybody know how you show a list of all the files/documents in a secure bucket, and provide a link to download each one?

    To give a little more detail:

    If I upload the assets in the back end - perch console by using the following 'FileUploadDownload' template:

    1. perch_content('FileUploadDownload');

    Which contains...

    1. <a href="<perch:content id="docs" type="file" label="File" bucket="secure" order="2">"><perch:content type="text" id="docTitle" label="Title" order="1" required title></a>

    Then I have no problem showing a list of the files to download by just calling the same template on any page that I want to show the links, with:

    1. perch_content('FileUploadDownload');

    Which is all fine.

    I've also allowed logged in members (front end) to upload files to the same secure bucket with perch forms, using the same ID ("docs"): with:

    1. perch_form('document-upload.html');

    Which contains the following...

    Then in the forms app I've pointed the File upload path to the same secure bucket ( /home/sites/secure ) which all works fine.

    The problem is...

    I can't seem to show ALL the files in this secure bucket regardless of where they are uploaded (backend console or logged in members in the front end)

    I want to give my logged in (front end) members the ability to see and download all the documents in this particular secure bucket.

    Hope that makes sense.

    Any ideas or pointers would be massively appreciated.

  • Resolved with:

    1. // Scan the directory - removes any .. (dots) & checks if files exist
    2. $mDir = '/home/sites/secure/';
    3. $mFiles = array_diff(scandir($mDir), array('..', '.'));
    4. if ($mFiles) {
    5. foreach ($mFiles as $mF) {
    6. echo '<a class="hover-2 more" href="/download?file=/' . $mF . '">' . $mF . '</a><br />';
    7. }
    8. } else {
    9. echo '<h3 class="text-red">No Documents Found</h3>';
    10. }

    Hope this is useful for somebody.