Moodle File API上传图片

I am currently working on Moodle and i am trying to upload an image and display it.

I followed all the steps explained here : https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#Simple_use and it is working.

For example if i upload a file with some text in it and i access the URL given by the make_pluginfile_url function it will display the text that is inside the file.

The problem is when i upload an image it doesn't display the image but some text like this :

(+�ء��\U�k���*�j~�Uܽ�U���W\Uت�k��zb��S�

I suppose it's because the File API treats the image as a text file and not as an .jpg.

Could someone tell me how i could make it display the image ?

Display it with html_writer class. Example:

html_writer::empty_tag('img', array('src'=> $url)); Where $url is valid url to your file. (Prepared with moodle_url::make_pluginfile_url() or similar)

empty_tag docs