Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Displaying files from assets/CustomFolder


Go to End


2 Posts   1699 Views

Avatar
Jonny123

Community Member, 2 Posts

9 April 2015 at 7:22am

Edited: 09/04/2015 7:23am

Hello,
I want to know how can i display all the files from assets/Custom Folder to Front-end ? with possibility for user to download them. Every user must log in before they can see those files listed, and every user will/can see different files(already done the module with linking files to users, the table looks like this in database ID | FileID | UserID )

Avatar
Nicolaas

Forum Moderator, 224 Posts

10 April 2015 at 1:04pm

Edited: 10/04/2015 1:11pm

Hi Johny

here are some basic ideas only:

Pseudo code goes like this:

MyPage_Controller {
  function Files(){
    $arrayList = ArrayList::create();
    $files = File::get()->filter("ParentID", $folder-ID);
    foreach($files as $file) {
      if($file->canView()) {
        $arrayList->push($file);
      }
    }
  }
}

in template:
<% loop Files %>
  <li><a href="$DownloadLink">$Title</a></li>
<% end_loop %>

Now all you need to do is to create a DownloadLink function on File. I'd actually google this or look in addons.silverstripe.org for any modules that include "forced" downloads (rather than views).

e.g see http://www.silverstripe.org/community/forums/general-questions/show/15832