如何在 Moodle 中存储文件以便外部应用程序可以访问该文件?
我需要在 Moodle 中存储一个文件。这实际上并不是一个问题,此处对此进行了解释。问题是每个人都必须可以访问该文件。因此,必须有一个 URL,例如 www.mymoodlesite.com/temp/myfile.txt 等,人们可以在浏览器中输入该 URL 并访问该文件。我想将文件复制到moodledata/temp文件夹中,但是我没有URL来访问该文件..
提前感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最后我可以解决我的问题:-)
我使用了这样的文件管理器:
然后像这样保存上传的文件:
然后可以像这样创建用于访问上传文件的URL:
Finally I could solve my problem :-)
I used a filemanager like this:
Then saved the uploaded file like this:
The URL in order to access the uploaded file can then be created like this:
假设您添加了如下元素:
现在假设您获得如下数据
请参阅下面的代码将文件上传到服务器中的指定文件夹。这与 Moodle 2.2+ 兼容,
我遇到了与您相同的问题,它解决了我的问题。
注意->请记住将您的上传文件夹 chmod 为 0777。
Assuming that you have added the element like this :
Now assuming that You get the data as the following
See the code below to upload the file to a specified folder in your server. This is compatible with moodle 2.2+
I faced the same problem that you're facing and it solved my problem.
N.B. -> Remember to chmod your upload folder to 0777.
如果满足以下条件,则无需经过身份验证即可访问通过 Moodle 的文件浏览器上传的文件
- 您的 Moodle 网站已将强制登录设置为“否”
- 您的文件已上传到首页站点文件中的文件。
上传的文件保存在moodledata/1/{filepath}中(假设是Moodle1.9)。由于您必须以编程方式执行此操作,因此您可以将它们存储在那里并使用 url /file.php/1/{filepath} 引用它们。换句话说。保存到 $CFG->datadir.'/1/'.filepath 的文件可通过 $CFG->wwwroot.'/file.php/1/'.filepath 访问;
或者,如果您不希望这些文件通过moodle文件浏览器显示在首页站点文件中,您可以编辑file.php以忘记检查位于特殊目录中的文件的权限,而只是提供它们。
希望这对这次编辑更有帮助。
You can access files uploaded through moodle's file browser without being authenticated if the following is true
- Your moodle site has forcelogin set to no
- Your file is uploaded the the files in frontpage sitefiles.
Uploaded files are saved (assuming Moodle1.9) in moodledata/1/{filepath}. Since you have to do it programatically you can store them there and reference them using the url /file.php/1/{filepath}. To say it another way. Files saved to $CFG->datadir.'/1/'.filepath are accessible with $CFG->wwwroot.'/file.php/1/'.filepath;
Alternatively if you don't want the files to show up in your front page site files through the moodle file browser you could edit file.php to forget checking permissions for files located in your special directory and instead just serve them up.
Hope this is more helpful with this edit.