Can not run the moodle file api.

Can not run the moodle file api.

by guotao li -
Number of replies: 1

How can i use moodle api methods, such sa get_file_browser()

and get_system_context()?

I got the error (PHP Fatal error: Call to undefined function

get_file_browser() in

/usr/share/moodle/browsfiles.php)

The following is the example from moodle file api:

<?php

$browser = get_file_browser();

$context = get_system_context();

$filearea = null;

$itemid = null;

$filename = null;

if ($fileinfo = $browser->get_file_info($context, $component, $filearea,

$itemid, '/', $filename)) {

        // build a Breadcrumb trail

        $level = $fileinfo->get_parent();

        while($level) {

               $path[] = array('name'=>$level->get_visible_name());

               $level = $level->get_parent();

        }

        $path = array_reverse($path);

        $children = $fileinfo->get_children();

        foreach($children as $child) {

             if($child->is_directory()) {

                    echo $child->get_visible_name();

                    // display contextid, itemid, component, filepath and filename

                    var_dump($child->get_params());

              }

        }

}

?>

Please help to solve the issue, much thanks!

Average of ratings: -
In reply to guotao li

Re: Can not run the moodle file api.

by Hardik Suba -

Hey, did you get the answer?

I have the same problem, I want to open some files in Android. I just want to show the user course files, no other operations.

Please, Share it if you got it this way or the other.