Ramaraju.d
Ramaraju.d

Reputation: 1353

How to upload a file to a folder location in drupal module?

How to upload a file to a folder location in drupal module way... I am creating a module(sample) in that i want to create a n upload file so that it should be stored in a particular location(folder).. with out using cck pls help me ... i coded like this

$form['pem_file_upload'] ['certificates'] = array (
  '#type' => 'file',
  '#value' => 'upload',
  '#title' => t('upload your certificate file'),
  '#description' => t('Upload the certificate file which is helpfull in sending push messages to ios device'),
  '#default_value' => variable_get('certificates', ''),
);

variable_set('certificates', $form_state['values'] ['certificates']);

$form['pem_file_upload'] ['certificates'] = array (
  '#type' => 'file',
  '#value' => 'upload',
  '#title' => t('upload your certificate file'),
  '#description' => t('Upload the certificate file which is helpfull in sending push messages to ios device'),
  '#default_value' => variable_get('certificates', ''),
);

variable_set('certificates', $form_state['values']['certificates']);

Upvotes: 3

Views: 2404

Answers (1)

DD dev
DD dev

Reputation: 176

for saving the file itself this is the function you need

$file = file_save_upload('pem_file_upload', array(), 'public://yourfolder' . variable_get('document_path', ''), FILE_EXISTS_RENAME);

    if ($file) {
        //Set the status of the uploaded file.
        $file->status = FILE_STATUS_PERMANENT;
        file_save($file);
}

public:// is a streams format and points to sites/all/default/files for more information see the drupal 7 file api

Upvotes: 4

Related Questions