简体   繁体   English

Moodle File API上传图片

[英]Moodle File API uploading an image

I am currently working on Moodle and i am trying to upload an image and display it. 我目前正在开发Moodle,并且正在尝试上传图片并显示它。

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. 我按照此处说明的所有步骤进行操作: https : //docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#Simple_use ,它正在运行。

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. 例如,如果我上传的文件中包含一些文本,并且我访问了make_pluginfile_url函数提供的URL,它将显示文件内部的文本。

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. 我想这是因为File API将图片视为文本文件而不是.jpg。

Could someone tell me how i could make it display the image ? 有人可以告诉我如何显示图像吗?

Display it with html_writer class. 用html_writer类显示它。 Example: 例:

html_writer::empty_tag('img', array('src'=> $url)); html_writer :: empty_tag('img',array('src'=> $ url)); Where $url is valid url to your file. 其中$ url是文件的有效URL。 (Prepared with moodle_url::make_pluginfile_url() or similar) (用moodle_url :: make_pluginfile_url()或类似文件准备)

empty_tag docs empty_tag文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM