create folders using taxonomy terms and use this field widget in file types . Use this folders to upload image in particular location instead of upload it in root.
use this code

if(!empty($file->field_folder) && empty($form_state['values']['replace_upload'])){
  $tname = taxonomy_term_load($file->field_folder['und'][0]['tid']);
  $file = file_move($file,$form_state['values']['scheme'] . '://'.$tname->name,FILE_EXISTS_RENAME);
}

in

  function file_entity_edit_submit($form, &$form_state)

and above the line of file_save($file);

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sri@re created an issue. See original summary.

sri@re’s picture

Issue summary: View changes
FileSize
46.86 KB
32.12 KB
41.71 KB
joseph.olstad’s picture

Issue summary: View changes
Issue tags: -https://www.drupal.org/node/2898547
Related issues: +#2898547: create folder using taxonomy for file upload in file_entity module

Please, only one open issue for same issue at the same time.
Improve issue summary formatting and refer to duplicate issue.

sri@re’s picture

Another solution to add file in folder. Created og group field in file types of image . And make that og group name as folder name and stored files in folder(og wise)wise.

if(!empty($file->og_group_ref)){
  $folder_name = node_load($file->og_group_ref['und'][0]['target_id']);
  $folder = strtolower($folder_name->title);dsm($folder);
  $folder = str_replace(' ', '_',$folder);
  if(is_dir($form_state['values']['scheme'] . '://'.$folder)){
     $file = file_move($file,$form_state['values']['scheme'] .'://'.$folder,FILE_EXISTS_REPLACE);
  }
  else{
    $mydir= $form_state['values']['scheme'] . '://'.$folder;
    file_prepare_directory($mydir, FILE_CREATE_DIRECTORY);
    $file = file_move($file,$mydir,FILE_EXISTS_REPLACE);
  }
}

in function file_entity_edit_submit($form, &$form_state) before the line of file_save.