如何在Moodle中存储文件,以便外部应用程序可访问? [英] How to store a file in Moodle so that it is accessible for an external application?

查看:113
本文介绍了如何在Moodle中存储文件,以便外部应用程序可访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Moodle中存储一个文件。这不是一个真正的问题,这是解释这里。问题是这个文件必须是每个人都可以访问的。因此,必须有一个URL,例如 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆