how to load a file into block?

Re: how to load a file into block?

by Davo Smith -
Number of replies: 0
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You cannot use the filepicker element in that way - you need to write some code to store the submitted file in a suitable location and then serve the file back to the end user.

You should look at the Moodle docs about this:

https://docs.moodle.org/dev/File_API
https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms

and have a look at a simple example:

https://github.com/AndyNormore/filemanager

You should also consider using a 'filemanager' element, instead of a 'filepicker'. The 'filepicker' is designed for files that you upload, process, then throw away (e.g. a CSV of user data that is used to update existing users, then is deleted). The 'filemanager' is designed for files that are uploaded, stored, then served back to end users.


Average of ratings: Useful (1)