Search code examples
drupaldrupal-7drupal-modulesdrupal-theming

file association with large amount of users


I am sorry if this is a dumb question I have the following code

function trc_upload_file() {

    $form['trc_upload_form'] = array(
        '#type'         =>  'managed_file',
        '#title'        =>  'Upload File',
        '#descripion'   =>  'Uplaod files',     
    );

    $form['#submit'][] = 'trc_upload_file_submit';
    return $form;       
}

function trc_upload_file_submit($form, &$form_state) {

    $file = file_load($form_state['values']['trc_upload_form']);    
    $file->status = FILE_STATUS_PERMANENT;
    file_save($file);

    /*file_usage_add($file, 'trc_upload_page', 'user', $account->uid);*/

    drupal_set_message(t('You Uploaded Successfully!'));

}

this is working fine how to use file_usage_add() function, can i use it for user_roles instead individual users.


Solution

  • As Clive has confirmed, this should work:

    file_usage_add($file, 'trc_upload_page', 'role', $roleID);

    Let us know how you get on,