脚本宝典收集整理的这篇文章主要介绍了php – 使用REST服务core_files_upload将文件上传到Moodle,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
contextid component filearea ITemid filepath filename filecontent
Moodle Web Services的文档不是很详细,所以我把我可以从Moodle论坛和GOOGLE搜索中拼凑起来,但我觉得我已经走到了尽头.从示例中我看到参数采用以下值:
contextid: int - not sure whether this is the userid component: "user" filearea: "PRivate" itemid: 0 filepath: "/" filename: "filename.jpg" filecontent: base64 encoding of file
我使用我的用户ID作为上下文 – 由于缺乏文档,我确认这是否正确.当我发布这个我收到错误:
{"exception":"moodle_exception","errorcode":"nofile","message":"File not sPEcified"}
我已经查看了“moodle / files / externallib.PHP”中定义的core_files_upload的位置,并且当filecontent不存在时会生成此错误消息.
我试过发布到测试脚本,我可以基于base64编码在Moodle服务器上成功创建图像,例如:
<?PHP file_put_contents('MyFile.jpg',base64_decode($_POST['filecontent']));
define('AJAX_SCRIPT',true); define('NO_MOODLE_COOKIES',true); require_once(dirname(dirname(__FILE__)) . '/config.PHP'); require_once($CFG->dirroot . '/webservice/lib.PHP'); echo $OUTPUT->header(); // authenticate the user $token = required_param('token',PARAM_ALPHANUM); $webservicelib = new webservice(); $authenticationinfo = $webservicelib->authenticate_user($token); // check the user can manage his own files (can upload) $context = context_user::instance($USER->id); $result = array("contextid"=>$context->id); echo json_encode($result);
希望这可以帮助任何面临同样问题的人.
以上是脚本宝典为你收集整理的php – 使用REST服务core_files_upload将文件上传到Moodle全部内容,希望文章能够帮你解决php – 使用REST服务core_files_upload将文件上传到Moodle所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。