General developer forum

 
 
Picture of Doncho Petrov
Showing pictures saved with filemanager
 

Yesterday I've implemented the filemanager functionality in my block. I succeeded to store picture files to mdl_files table and to show the already stored pictures using the file_postupdate_standard_filemanager() and file_prepare_standard_filemanager().

And here comes the problem...

How can I show/render these pictures on the front end???

I was researching the whole day and I've come to the conclusion that maybe file_rewrite_pluginfile_urls() is the right function to use, but I was unable to run it properly. It expects a text param that converts to url maybe, but I don't think I have any text to pass.

Can somebody please give me some clarification how to achieve my goal here?

Thanks in advance.

 
Average of ratings: -
Davo
Re: Showing pictures saved with filemanager
Group DevelopersGroup Particularly helpful Moodlers

$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.

 
Average of ratings: -
Picture of Doncho Petrov
Re: Showing pictures saved with filemanager
 

It worked like a charm.

Thanks a lot! : )

 
Average of ratings: -