General developer forum

Moodle mform editor file upload

Picture of Sandipa Mukherjee
Moodle mform editor file upload


I am facing trouble to use file handling in mform editor using File API in Moodle forms

In description_form.php, I have added 

$editoroptions = $this->_customdata['editoroptions'];

$mform->addElement('editor', 'textfieldup_editor', get_string("desc_up", "local_myplugin"), null, $editoroptions);


in description.php, I have added 

$editoroptions = array('trusttext' => true, 'maxfiles' => $maxfiles, 'maxbytes' => $CFG->maxbytes, 'context' =>context_course::instance($courseid),

        'subdirs' => file_area_contains_subdirs($context, 'local_myplugin', 'entryup', $entry->id));

after that I have create the object of my description form and process the data like this

if ($my_desc_form = $mform->get_data()) { 

if (!empty($my_desc_form->textfieldup_editor)) {

        $entry = file_postupdate_standard_editor($my_desc_form, 'textfieldup', $editoroptions, context_course::instance($courseobj->id),     'local_myplugin', 'up', $entry->id);

        $up_definition = file_rewrite_pluginfile_urls($date_table_desc_form->textfieldup_editor["text"], 'pluginfile.php', 30, 'local_myplugin', 'up', 3);


    set_config("desc_up_",  $my_desc_form->textfieldup_editor['text'], "local_myplugin");


I can not retrieve perfect image url  from file_rewrite_pluginfile_urls(). 

Does any one help me regarding this?

Thanks and Regrads,



Average of ratings: -
Re: Moodle mform editor file upload
Core developersParticularly helpful MoodlersPlugin developers

Does your plugin lib.php have a PLUGINNAME_pluginfile function to check permissions and serve the file to the browser? (See any core activity plugin for examples)

Average of ratings: -
Picture of Sandipa Mukherjee
Re: Moodle mform editor file upload
Thanks for this reply. I don't have such type of function in my lib.php. My first problem is when I upload file in editor [Please see the screenshot]

Then the absolute file is saved in config_plugins folder. When I retrieve this entire information form database, then admin user can see the file if he/she uploaded this. Other user can not see the file. 

Please see the database instance screenshot

Average of ratings: -