Feltöltés form saját útvonallal

makgab képe

Üdv!

Mivel lehetne megoldani, hogy a userek fájlokat (pdf,doc) tudjanak feltölteni egy adott könyvtárba?
A sites/default/files alatt kellene egy saját könyvtárba. A webform modul nem jó, mert - ha jól láttam - csak a webform/ könyvtár alá engedi. Nekünk meg egy saját (egyedi) útvonalra kellene, pl.: "sites/default/files/Fokonyvtar/alkonyvtar"

Mit javasoltok?

Drupal verzió: 
makgab képe

Ha esetleg modult kell írni hozzá, akkor mintának jó lehet ez:

<?php
# import modul

# import.install
function import_install() {
  $dir_docs_created = drupal_mkdir('public://docs/');
  if ($dir_docs_created === FALSE) {
  drupal_set_message(st('The directory public://docs/ could not be created. Please contact your site administrator.'), 'warning');
  }
}
 
 
# import.module
function import_permission() {
  return array(
    'administer import' => array(
    'title' => t('Administer files import'),
    'description' => t('Import files.'),
    ),
  );
}
 
function import_menu() {
  $items = array();
  $items['admin/config/content/imports'] = array(
  'title' => 'Import file',
  'description' => 'Import a file.',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('import_form'),
  'access arguments' => array('administer import'),
  'file' => 'import.admin.inc',
  );
return $items;
}
 
 
# import.admin.inc
function import_form($form, &$form_state) {
  $form = array();
 
  // Use the #managed_file FAPI element to upload a file.
  $form['file_fid'] = array(
    '#title' => t('File'),
    '#type' => 'managed_file',
    '#description' => t('The uploaded file will be processed.'),
    '#default_value' => variable_get('file_fid', ''),
    '#upload_validators' => array(
    'file_validate_extensions' => array('put-in-your-file-extention'),
    ),
  '#upload_location' => 'public://docs/',
  '#process' => array('import_my_file_element_process')
);
 
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
 
  return $form;
}
 
/* It disables the default upload button that comes with this #managed_file form */
function import_my_file_element_process($element, &$form_state, $form) {
  $element = file_managed_file_process($element, $form_state, $form);
  $element['upload_button']['#access'] = FALSE;
 
return $element;
}
 
 
function import_form_submit(&$form, &$form_state) {
  // Load the file.
  $file = file_load($form_state['values']['file_fid']);
  // Change status to permanent.
  $file->status = FILE_STATUS_PERMANENT;
  // Save.
  $uploaded = file_save($file);
  if ($uploaded == TRUE) {
    drupal_set_message(t('The file has been uploaded.'));
  }
  else {
    drupal_set_message(t('The file could not be uploaded. Please contact the site administrator.'), 'error');
  }
 
  $file_path = $file->uri;
 
  //Function call to process file contents.
  csv_import_create_node($file_path);
}
?>

// drupal_flush_all_caches();
0
0
Illyés Edit képe

Tartalomtípushoz fájl mező, és annak megadhatod a célkönyvtárát. A célkönyvtár útvonalában lehet tokeneket is használni.

0
0
makgab képe

Igen, ez jó is lehet. Én is javasoltam ezt a lehetőséget.
De csak simán egy feltöltés funkció kell.

0
0
pp képe

IMCE modul ha ez kell.

A sample profile pont egy ilyen beállítást tartalmaz. Ha engedélyezed a felhasználóknak, akkor mindenkinek lesz egy File Browser tab a profil oldalán és a u+uid mappába fog dolgozni.

Akár közös mappa is létrehozható nekik pluszba.

pp

2
0