How to get images of question and options . I am creating custom web-services.

Re: How to get images of question and options . I am creating custom web-services.

by Baiju Sharma -
Number of replies: 0

Hi, I am using this File API for reading images stored path inside OUTPUT:"/home/onlin200/moodledata32/filedir/ce/2b/ce2b454fcdf9601f75065cd794df46d20006b932"

Requirement: Read data from the above file path covert this data into base_encode and send data to web services.

Just want to know, is it possible to read all data from "ce2b454fcdf9601f75065cd794df46d20006b932" This is an image file.

Below is my code:

 $filename  = "baijuabcd.jpg";

        $component = "user"; //if activity: database

        $filearea  = "draft";

        $itemid    = 824469588;// ID from table mdl_question (for activity: database) - row in the table where the above $text is stored


        if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, '/', $filename)) {

            $level  = $fileinfo->get_parent();

            $params = $fileinfo->get_params();

            $fs     = get_file_storage();            

            $file = $fs->get_file($params['contextid'], $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']);    

            if ($file) {

                $contenthash = $file->get_contenthash();

                $l1          = $contenthash[0] . $contenthash[1];

                $l2          = $contenthash[2] . $contenthash[3];

                $location    = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash;

                echo $location;            

            }

OUTPUT:"/home/onlin200/moodledata32/filedir/ce/2b/ce2b454fcdf9601f75065cd794df46d20006b932"

Kindly, help.