2012-03-20 81 views
2

如何上傳文件到drupal模塊文件夾位置的方式... 我正在創建一個模塊(示例),我想創建一個上傳文件,以便它應該存儲在特定的位置(文件夾)。 。使用CCK請幫我...我編寫這樣如何將文件上傳到drupal模塊中的文件夾位置?

$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']); 

回答

2

用於保存文件本身,這是你需要

$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); 
} 

公共功能://是一個流格式和點到sites/all/default/files 欲瞭解更多信息,請參閱drupal 7 file api

相關問題