Quantcast
Channel: Web services
Viewing all articles
Browse latest Browse all 2362

error api for uploading image of course

$
0
0
by Hatem Ghaly.  

hello 

I have the following code

<?php
 $token = 'xxxxxxxxxxxx';
 $domainname = 'xxxxxxxxxxxxxxxxxxx';
 $restformat = 'json';
require_once('curl.php'); //Download this file
$curl = new curl;
$path = 'moodle.png';
$type = pathinfo($path, PATHINFO_EXTENSION);

$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$params = array(
    'component' => 'course',
    'filearea' => 'overviewfiles',
    'itemid' => 0,
    'filepath' => '/',
    'filename' => 'moodle1.png',
    'filecontent' => $base64,
    'contextlevel' => 'course',
    'instanceid' => 2,

);

/// UPLOAD IMAGE - Moodle 3.10+ and later
$functionname = 'core_files_upload';
$serverurl = $domainname .'/webservice/rest/server.php' . '?wstoken=' . $token .'&wsfunction=' . $functionname;

$restformat = ($restformat == 'json') ?
'&moodlewsrestformat=' . $restformat : '';
//
printf("\n");
printf("\n");

$resp = $curl->post($serverurl . $restformat, $params);
$resps = json_decode($resp);

print_r($resps);
printf("\n");


========================

the response is 
stdClass Object ( [exception] => coding_exception [errorcode] => codingerror [message] => Coding error detected, it must be fixed by a programmer: File can be uploaded to user draft area only )

==================
why???


Viewing all articles
Browse latest Browse all 2362

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>