Showing pictures saved with filemanager

Re: Showing pictures saved with filemanager

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

$fs = get_file_storage();

$files = $fs->get_area_files(/* Insert file area details here */);

foreach ($files as $file) {

$imgurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());

echo "<img src='{$imgurl}' />';

}

You'll also need to edit your plugins lib.php file and add a [pluginname]_pluginfile() function - see mod/forum/lib.php, function 'forum_pluginfile' for an example.