Uploading files in a forum with a Web Service in Moodle -


i need upload files forum in moodle through web services, have been searching , found exist ws called core_files_upload(). looked @ code of ws , context level of ws (block, course, coursecat, system, user or module), context forum not exist , ws deprecated.

i found in moodle 3.0 there 2 new ws related forums, mod_forum_add_discussion , mod_forum_add_discussion_post looked @ code , don't allow upload.

then decided best solution create new one, don't know uploading files in moodle , can't find information. i'm little bit familiar structure of ws in moodle because have made 2 simple ws don't know how this.

if knows how or have examples or documentation may useful, helpful.

thanks in advance.

you can file

/webservice/upload.php

    file uploading files  $params = array('token'=>$token, 'filepath' => $filepath                 , 'filearea'=>'draft') + $_files ;     $serverurl = <domainname>. '/webservice/upload.php'. '?token=' . $token;     $ch = curl_init();     curl_setopt($ch, curlopt_header, 0);     curl_setopt($ch, curlopt_verbose, 0);     curl_setopt($ch, curlopt_returntransfer, true);     curl_setopt($ch, curlopt_useragent, "mozilla/4.0 (compatible;)");     curl_setopt($ch, curlopt_url, $serverurl);     curl_setopt($ch, curlopt_post, true);     curl_setopt($ch, curlopt_postfields, $params);     $response = curl_exec($ch);   

or can code can you, create file in moodle data , record in file table temp file.

$fs = get_file_storage();  $target_path = <target-path>; $context = get_context_instance(context_user, $userid, must_exist); $cm         = get_coursemodule_from_instance('forum', $forum->id);     $modcontext = context_module::instance($cm->id, must_exist);  //saving in draft $item = rand(); $file_record = array('contextid'=>$context->id, 'component'=>'user', 'filearea'=>'draft', 'itemid'=>$item, 'filepath'=>"/", 'filename'=><filename>, 'userid'=>$userid); $fs->create_file_from_pathname($file_record, $cfg->dirroot."/".$target_path.<filename>);  // saving post $file_record = array('contextid'=>$modcontext->id, 'component'=>'mod_forum', 'filearea'=>'post', 'itemid'=>$post->id, 'filepath'=>"/", 'filename'=><filename>, 'userid'=>$userid); $fs->create_file_from_pathname($file_record, $cfg->dirroot."/".$target_path.$imagefileenc); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -