2016-09-28 119 views
0

我需要將附件輸入添加到moodle註冊表單
此文件輸入不被moodle通過標準user profile fields支持。定製moodle註冊表單

於是,我就手動添加:
我說:

$mform->addElement('file', 'attach', "Attach", null,array('accepted_types' => 'pdf')); 
$mform->setType('attach', PARAM_RAW); 
$mform->addRule('attach', 'Missing File Attachment', 'required', null, 'client'); 

但我應該在哪裏告訴Moodle自己將該值插入數據庫?

回答

0

你可能應該先添加自定義用戶配置文件字段中,描述here。在這裏,你應該重寫功能profile_save_data($usernew)告訴您要保存文件的文件系統。
如果您想了解如何從表單文件並保存它,你可以去here。特別是,你可以使用filepicker表單元素,它取代了舊file元素,

$mform->addElement('filepicker', 'userfile', get_string('file'), null, 
        array('maxbytes' => $maxbytes, 'accepted_types' => 'pdf')); 


獲取文件的內容和文件名以及商店它:

$content = $mform->get_file_content('userfile'); 
$name = $mform->get_new_filename('userfile'); 
$success = $mform->save_file('userfile', $fullpath, $override); 

其中$fullpath是在文件系統正的路徑(如moodledata文件夾)和$override是一個布爾值,意思是「是否存在覆蓋文件」。
免責聲明:我沒有嘗試這種解決方案我自己。