使用带有Moodle表单的文件Api可以从外部moodle项目访问文件

时间:2021-12-16 11:20:07

Need Help,

I have a deadline coming up and I am stuck in this,

我有一个截止日期,我被困在这里,

I am totally lost while trying to do the following task: store file uploaded by user from moodle form and access (also download) it from a project outside moodle.

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

Detailed scenario :

详细方案:

A user will make requests by filling up the requests' form (request form is different for each type of request). User will have to upload following files from the moodle form: * Receipt * Supporting docs

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

Folders where the files need to be stored: On the server:

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

  • Uploads/Performa/Request_cardissuance/requestid.pdf
  • Uploads/Performa/Request_degreeissuance/requestid.pdf (Performa is the pdf form the of the request form)
  • 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

A separate php project will have table:

一个单独的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 ]

[高级否|请求ID |请求类型ID | Performa |收据|支持文档|动作| 1 | 1 | 1 | (链接,点击时下载pdf文件)| do | do | action link]

I have Made the moodle form for it and added the filemanager element:

我为它制作了moodle表单并添加了filemanager元素:

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

What do I have to do in the view.php after this:

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

$fromform=$form->get_data() ;

<a href="http://*.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()**

Using moodle v2.4.

使用moodle v2.4。

Your Help will be much appreciated.

非常感谢您的帮助。

1 个解决方案

#1


0  

I think you might want to use the filepicker for each file rather than the filemanager. Then save the files into the folders above.

我想你可能想要为每个文件使用filepicker而不是filemanager。然后将文件保存到上面的文件夹中。

$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

I would recommend using a folder outside of the web root though, unless the documents are public?

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

#1


0  

I think you might want to use the filepicker for each file rather than the filemanager. Then save the files into the folders above.

我想你可能想要为每个文件使用filepicker而不是filemanager。然后将文件保存到上面的文件夹中。

$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

I would recommend using a folder outside of the web root though, unless the documents are public?

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