5

Taking a look at Assets 2.0 docs I can see that with the {exp:assets:folders} tag we can determine the folder where the photos are uploaded in a simple file uploading field, my question is if the same can be done with the regular assets field, so that when the users click on the button to add files they can see only the pre-determined folder and its subfolders? If this is possible then what is the code? I've only used a simple {field:field_name} to load Assets inside Safecracker so I'm not familiar with more complex solutions.

Thank you!

1

If you look at the field settings for your Assets field, you should see the option to restrict the available upload directories there.

| improve this answer | |
  • 1
    That's not what I need, unfortunately. The idea is to give each user his own upload directory, so even if I restrict directories there the user will still have to see the directories of all the other users, which I don't want. For that reason the folder restrictions have to be done inside safecracker, so that the user can only see his own directory. – Isabel Jan 16 '13 at 11:42
  • Maybe can you change the title of your question then. Something more specific like "Restrict upload directory to member using Assets and Safecracker". This helps others who might look for a similar solution. – GDmac Jan 16 '13 at 12:23
1

I've got a deeper implementation of this, however as a basis you can hack Assets 2.1 to only show files uploaded by the logged in member when working with standard EE file sources.

First, add a 'member_id' column to the assets_files table:

ALTER TABLE  `exp_assets_files` ADD  `member_id` INT( 10 ) UNSIGNED NULL

Modify assets/sources/base_source.php (line 605) to add the member_id to the db table:

'file_name' => $filename,
'member_id' => $this->EE->session->userdata('member_id'), // Add 'member_id' to database
'kind' => Assets_helper::get_kind($filename)

Finally, modify assets/libraries/assets_lib.php (line 712) to limit the display of files to the currently logged in member only:

Change this existing line:

$this->EE->db->where_in('exp_assets_files.folder_id', $full_folder_list);

To this:

$this->EE->db->where_in('exp_assets_files.folder_id', $full_folder_list)->where('member_id', $this->EE->session->userdata('member_id'));
| improve this answer | |
  • This is just a basic limiting example, I'm working on documenting our internal changes (we've added fieldtype params that can limit to session, member_id, entry_id) and will comment back here with a link to our implementation docs. – Michael P Apr 18 '13 at 0:02
  • I would love to see your implementation docs if you've ever gotten them around. – adrienne Dec 13 '13 at 18:34
  • the user can still overwrite another users file if the filenames are identical. otherwise works great. – Richard Frank Jun 10 '14 at 19:34

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.