edgar.dueñas
Enviado por edgar.dueñas el Mié, 11/05/2016 - 13:05

Como subir una imagen en profile de Drupal, esto lo logramos mediante esta funcion function MODULE_pics_form

<?php
 
function MODULE_pics_form($form, &$form_state) {
 
  // Attach User Picture upload
  $form['picture']['profile'] = array(
    '#type' => 'file',
    '#title' => t('Profile picture')
  );
 
  $form['submit'] = array('#type' => 'submit','#value' => 'Submit');
 
  return $form;
}
 
 
function MODULE_pics_form_validate($form, &$form_state) {
  $file = file_save_upload('profile', array(
      'file_validate_is_image' => array(),
      'file_validate_extensions' => array('png gif jpg jpeg'),
  ));
  if ($file) {
    if ($file = file_move($file, 'public://')) {
      $form_state['values']['profile'] = $file;
    }
    else {
      form_set_error('profile', t('Failed to write the uploaded file the site\'s file folder.'));
    }
  }
  else {
    form_set_error('profile', t('No file was uploaded.'));
  }
}
 
function MODULE_pics_form_submit($form, &$form_state) { 
  global $user;
  $uid = $user->uid;
  $account = user_load($uid);
 
  $file = $form_state['values']['profile'];
  unset($form_state['values']['profile']);
  $file->status = FILE_STATUS_PERMANENT;
  file_save($file);
 
  $edit['picture'] = $file;
  user_save($account, $edit);
 
}
 
?>