public function send_relative_file(stored_file $mainfile, $relativepath) {
        global $CFG;
        // Check if this repository is allowed to use relative linking.
        $allowlinks = $this->supports_relative_file();
        if (!empty($allowlinks)) {
            // Get path to the mainfile.
            $mainfilepath = $mainfile->get_source();

            // Strip out filename from the path.
            $filename = $mainfile->get_filename();
            $basepath = strstr($mainfilepath, $filename, true);

            $fullrelativefilepath = realpath($this->get_rootpath().$basepath.$relativepath);

            // Sanity check to make sure this path is inside this repository and the file exists.
            if (strpos($fullrelativefilepath, realpath($this->get_rootpath())) === 0 && file_exists($fullrelativefilepath)) {
                send_file($fullrelativefilepath, basename($relativepath), null, 0);
            }
        }
        send_file_not_found();
    }
public function send_relative_file(stored_file $mainfile, $relativepath) {
        global $CFG;
        // Check if this repository is allowed to use relative linking.
        $allowlinks = $this->supports_relative_file();
        if (!empty($allowlinks)) {
            // Get path to the mainfile.
            $mainfilepath = $mainfile->get_source();

            // Strip out filename from the path.
            $filename = $mainfile->get_filename();
            $basepath = strstr($mainfilepath, $filename, true);

            $fullrelativefilepath = realpath($this->get_rootpath().$basepath.$relativepath);

            // Sanity check to make sure this path is inside this repository and the file exists.
            if (strpos($fullrelativefilepath, realpath($this->get_rootpath())) === 0 && file_exists($fullrelativefilepath)) {
                send_file($fullrelativefilepath, basename($relativepath), null, 0);
            }
        }
        send_file_not_found();
    }
public function send_relative_file ( stored_file $ mainfile , $ relativepath ) { global $ CFG ; // Check if this repository is allowed to use relative linking. $ allowlinks = $ this -> supports_relative_file ( ) ; if ( ! empty ( $ allowlinks ) ) { // Get path to the mainfile. $ mainfilepath = $ mainfile -> get_source ( ) ; // Strip out filename from the path. $ filename = $ mainfile -> get_filename ( ) ; $ basepath = strstr ( $ mainfilepath , $ filename , true ) ; $ fullrelativefilepath = realpath ( $ this -> get_rootpath ( ) . $ basepath . $ relativepath ) ; // Sanity check to make sure this path is inside this repository and the file exists. if ( strpos ( $ fullrelativefilepath , realpath ( $ this -> get_rootpath ( ) ) ) === 0 && file_exists ( $ fullrelativefilepath ) ) { send_file ( $ fullrelativefilepath , basename ( $ relativepath ) , null , 0 ) ; } } send_file_not_found ( ) ; }
Gets a file relative to this file in the repository and sends it to the browser.

@param stored_file $mainfile The main file we are trying to access relative files for.
@param string $relativepath the relative path to the file we are trying to access.
Gets a file relative to this file in the repository and sends it to the browser .