【问题标题】:Using File Api with Moodle Form to make files accessible from outside moodle project使用带有 Moodle 表单的 File Api 使文件可以从外部 moodle 项目访问
【发布时间】:2013-10-08 13:27:44
【问题描述】:

需要帮助,

我的最后期限快到了,我被困在这个问题上,

在尝试执行以下任务时我完全迷失了:存储用户从moodle表单上传的文件并从moodle之外的项目访问(也下载)它。

详细场景:

用户将通过填写请求表单来提出请求(每种请求类型的请求表单都不同)。用户必须从 Moodle 表单上传以下文件:* 收据 * 支持文档

需要存放文件的文件夹:服务器上:

  • Uploads/Performa/Request_cardissuance/requestid.pdf
  • Uploads/Performa/Request_degreeissuance/requestid.pdf (Performa 是申请表的 pdf 格式)
  • Uploads/Receipt/Request_cardissuance/requestid.jpg
  • Uploads/Receipt/Request_degreeissuance/requestid.jpg
  • Uploads/Supporting_docs/Request_cardissuance/requestid.zip
  • Uploads/Supporting_docs/Request_degreeissuance/requestid.zip

一个单独的php项目会有表:

[ Sr. No | Request ID | Request Type ID | Performa | Receipt| Supporting Docs | Action| 1 | 1 | 1 | (link , when clicked downloads the pdf file)|do|do|action link ]

我已经为它制作了moodle表单并添加了文件管理器元素:

$mform->addElement('filemanager', 'receipt', get_string('receipt_file'), null,
                   array('maxbytes' => $CFG->maxbytes, 'accepted_types' => '*'));

在这之后我要在view.php中做什么:

$fromform=$form->get_data() ;

<a href="http://stackoverflow.com/questions/6666572/how-to-store-a-file-in-moodle-so-that-it-is-accessible-for-an-external-applicati">this</a> is what I followed but I get a server error on calling function **get_new_filename()**

使用moodle v2.4。

我们将非常感谢您的帮助。

【问题讨论】:

  • 祝你好运。我还花了很多时间管理 Moodle 插件中的上传...最终我让我的用户使用 FTP 上传文件,然后他们可以从文件系统存储库 (docs.moodle.org/22/en/File_system_repository) 中获取它们。无论如何,课程和相关文件是否仅对经过身份验证的用户可用?

标签: php forms file moodle


【解决方案1】:

我认为您可能希望对每个文件使用文件选择器而不是文件管理器。然后将文件保存到上面的文件夹中。

$mform->addElement('filepicker', 'receipt', get_string('receipt_file'), null,
               array('maxbytes' => $maxbytes, 'accepted_types' => '*'));
...
$id = $DB->insert_record(...)
$fullpath = "Uploads/Performa/Request_cardissuance/request{$id}.pdf";
$override = true;
$success = $mform->save_file('receipt', $fullpath, $override);

http://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#filepicker

我建议使用 Web 根目录之外的文件夹,除非文档是公开的?

【讨论】:

  • 它不工作。是的,谢谢你的推荐,我已经在网络根目录之外创建了文件夹
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-04
相关资源
最近更新 更多