Getting an image from course format options

Re: Getting an image from course format options

by Tony Alexander Hild -
Number of replies: 5

Hi Cristian,

You're right. Only the user that saved the file can see it on the config. I'll give a try to fix this.


Thanks

In reply to Tony Alexander Hild

Re: Getting an image from course format options

by Saran Gokul -

Hi,

I am trying to create a new course format and add a header image for a course if the format selected is the new format. I followed all the steps to store the header image. The header image is getting stored as a int in the table mdl_course_format_options as name 'headerimage' and value '295861144'.

However, I am unable to display the saved image  in the course page. 

I try to output the file with a format as below to start with.

echo "<img src='".$CFG->wwwroot."/pluginfile.php/".$context->id."/format_enhancedtimeline/headerimage/295861144/2_enhamcedtimeline_banner.png'>";
But the image displays is broken. I am unable to spot the error. Please help.


Thanks in advance.

In reply to Saran Gokul

Re: Getting an image from course format options

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Is it as simple as a typo in your code

echo "<img src='".$CFG->wwwroot."/pluginfile.php/".$context->id."/format_enhancedtimeline/headerimage/295861144/2_enhamcedtimeline_banner.png'>";
enhancedtimeline and enhamcedtimeline?
In reply to Richard Oelmann

Re: Getting an image from course format options

by Saran Gokul -

Hi,

Thanks for the response. 

It was not a typo. I figured out the way to get the file displayed forming the correct url.

I am facing a different issue now. I would like to restrict the number of file uploads to 1 and accepted types as jpg or png or gif.


$options = array(
'maxfiles' => 1,
'maxbytes' => $CFG->maxbytes,
'subdirs' => 0,
'accepted_types' => array('.jpg','.gif','.png')
);

 'headerimage' => array(
'label' => new lang_string('headerimage','format_timeline'),
'element_type' => 'filemanager',
'element_attributes' => array(
),
'options' => $options,
'help' => 'headerimage',
'help_component' => 'format_timeline',

)
But this is not working. Any help please.


Thanks,

Saran



In reply to Saran Gokul

Re: Getting an image from course format options

by Cristian Martin Nieto -

Hey Saran,


Try to make your 'element_attributes' variable to look like this:

 'headerimage' => array(
     'label' => new lang_string('headerimage','format_timeline'),
     'element_type' => 'filemanager',
     'element_attributes' => array(null,
                             array(
                                   'subdirs' => 0,
                                   'maxfiles' => 1,
                                   'accepted_types' => array('.jpg', '.gif', '.png')
                             )),
     'help' => 'headerimage',
     'help_component' => 'format_timeline',

)

And remove the 'options' variable.

In reply to Cristian Martin Nieto

Re: Getting an image from course format options

by Saran Gokul -

Thanks a lot Cristian !!! Worked like a charm smile