0

If I had a folder with a series of subfolders that matched the username, could I show those files to that specific user? Looking to try making a download portal, but the files are not small enough to be uploaded through PHP. Example:

File Manager Settings:

/home/www/files/

Assets Folder tag: parent_folder="{filedir_x}"

But I wanted to show a single folder in the files directory:

/home/www/files/{username}

Assets Folder tag: parent_folder="{filedir_x}{username}"

The entire tag would look like this:

{exp:assets:folders parent_folder="{filedir_20}admin" recursive="yes"}
    <h3>{folder_name}</h3>
    <ul>
        {exp:assets:files folder_id="{folder_id}"}
            <li><a href="{url:huge}" target="_blank">{if title != ""}{title}{if:else}{filename}{/if}</a></li>
        {/exp:assets:files}
    </ul>
{/exp:assets:folders}

Using just {filedir_x} worked, but adding {filedir_x}{username} did not. Is it possible without using entries and just the two Assets tags? And I would assume from previous posts that if it could, it would show all files as a flat list, and not nested within subfolders?

  • Blair, I'm curious if you successfully got this working. I'm looking into doing something very similar. Also, if you were able to get this up and running can you confirm if the {exp:assets:files} tag output indeed produced a flat list and not nested subfolders. Thanks. – Brett Burwell Aug 5 '13 at 21:50
  • Posted the answer below, hope it helps! – Blair Aug 6 '13 at 2:06
3

Blair,

when Expression Engine calls Assets module tags, {username} is still just a string saying "{username}" (see Low's excellent overview for parse order - http://bit.ly/UwfZE2). You'll have to get the username using a different approach - probably by using PHP on Input.

| improve this answer | |
1

(To answer a request on what I did) I used a list of folder that .load a template of files like so:

URL: site.com/downloads/me/blair Username is required in the URL so the segment variable can be used to parse early enough. logged_in_username won't work alone. There are addons to get around this, might do that in the future, but I couldn't find a native EE way.

File Directory: home

- blair
- - Folder 1
- - - file1
- - - file2
- - - file3
- - Folder 2
- - - file4

Folders:

<ul>
  {exp:assets:folders parent_folder="{filedir_29}{segment_3}" recursive="no"}
  <li>
    <a href="{path='downloads/_assets'}/{folder_id}/{username}">{folder_name}</a>
    {if total_subfolders}
      <ul>
      {subfolders}
      </ul>
    {/if}
  </li>
  {/exp:assets:folders}
</ul>

Files: URL: site.com/downloads/me/1234 (folder id)

{exp:assets:files folder_id="{segment_3}"}
    {exp:link_vault:download_link file_path='{server_path}' text="{filename}"}
      {!-- File display stuff --}
      {!-- Ex: --}
      {server_path} - {filename}...etc. 
    {/exp:link_vault:download_link}    
{/exp:assets:files}

I also have some protection, such as wrapping it in a {if segment_3 !=""} so it won't show every single folder (kaboom!) and {if segment_3 != logged_in_username}. We've also added member_group=="1" to that last conditional so we can check other users list of files quickly, and we don't run a public system to worry about security, all campus internal stuff. Link vault to track downloads and there's another template to post files publicly that does need link limitations & hiding. enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.