如何在Moodle中存储文件,以便外部应用程序可访问? [英] How to store a file in Moodle so that it is accessible for an external application?
问题描述
www.mymoodlesite.com/temp/myfile.txt
之类的,可以在一个浏览器中输入并访问该文件。我想将文件复制到moodledata / temp文件夹中,但是我没有一个URL来访问该文件。 感谢您的帮助!
最后我可以解决我的问题: - )
我使用了一个像这样的文件管理器:
$ mform-> addElement('filemanager','my_filemanager','Upload a file ',null,array('maxbytes'=> $ CFG-> maxbytes,'maxfiles'=> 1,'accepted_types'=> array('* .zip')));
然后保存上传的文件如下:
if($ draftitemid = file_get_submitted_draft_itemid('my_filemanager')){
file_save_draft_area_files($ draftitemid,$ context-> id,'mod_assignment','my_filemanager',0, array('subdirs'=> false,'maxfiles'=> 1));
$ / code>
为了访问上传文件的URL可以这样创建:
file_encode_url($ CFG-> wwwroot。'/pluginfile.php','/'。$ this->上下文 - > id。'/ mod_assignment / my_filemanager');
I need to store a file in Moodle. This is not really a problem, it is explained here. The problem is that this file has to be accessible for everyone. Hence, there has to be a URL, e.g. www.mymoodlesite.com/temp/myfile.txt
or the like, which one can enter in ones browser and access the file. I thought of copying the file into the moodledata/temp folder, but then I do not have a URL in order to access the file..
Thanks for your help in advance!
Finally I could solve my problem :-)
I used a filemanager like this:
$mform->addElement('filemanager', 'my_filemanager', 'Upload a file', null, array('maxbytes' => $CFG->maxbytes, 'maxfiles' => 1, 'accepted_types' => array('*.zip')));
Then saved the uploaded file like this:
if ($draftitemid = file_get_submitted_draft_itemid('my_filemanager')) {
file_save_draft_area_files($draftitemid, $context->id, 'mod_assignment', 'my_filemanager', 0, array('subdirs' => false, 'maxfiles' => 1));
}
The URL in order to access the uploaded file can then be created like this:
file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/mod_assignment/my_filemanager');
这篇关于如何在Moodle中存储文件,以便外部应用程序可访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!