Filepicker: Reading file content

Re: Filepicker: Reading file content

by Paul K -
Number of replies: 3

Dear Davo,

you are right that conceptionally the above mentioned code doesn't make much sense. However I have published it to present the main goal which I would like to achieve.

It will be good if someone can share some working code in which the function get_file_content has been used.

Thanks and best

Paul

In reply to Paul K

Re: Filepicker: Reading file content

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Paul,

How about this example of get_file_content from Moodle core:

https://github.com/moodle/moodle/blob/master/admin/tool/uploadcourse/index.php#L42

In this file, it creates an instance of the tool_uploadcourse_step1_form (defined here: https://github.com/moodle/moodle/blob/master/admin/tool/uploadcourse/classes/step1_form.php#L42 ), then checks to see if it has been submitted ($mform1->get_data()), then calls get_file_content() on the $mform instance.



Average of ratings: Useful (2)
In reply to Davo Smith

Re: Filepicker: Reading file content

by Paul K -

Dear Davo,


thank you for this hint. I'm only wondering how to do this with a plugin when the form class definition extends the moodleform_mod which doesn't posses the definition of get_file_content function. From the logical point of view the plugin have the mod_form.php file with the plugin class definition and the lib.php with the functions, responsible for adding and updating the plugin instance.

I assume that the best way to read the configuration file will be to extend the lib.php file by adding additional function which will get the content of the file at the time of creating or editing the plugins value. My question is only how the read the content of file using a function defined in lib.php?

I will appreciate for any suggestion.

Paul


In reply to Paul K

Re: Filepicker: Reading file content

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If this is on the mod_form, then processing the file and then throwing it away feels like the wrong approach.

Most activity plugins use a filemanager element, not a filepicker element there, then stores the file using the API (and possibly does some processing on it when submitted).

See mod/resource for an example (or mod/scorm, if you want a more complex example where some processing is done on the submitted file).