LMSouq
moodle-core Open

Getting the real URL of files uploaded in Moodle

JO
John Kulova
1 month ago
3 views
Problem Description
I am trying to get the url to a file that I have uploaded to moodle. I want to access the file via the browser using http. The pathname of the file is hashed in the moodle database. Is there a way of getting the real url of uploaded files in moodle? this is the code I was trying out using the Moodle File API. <?php require_once("../config.php"); $course_name=$_GET["course"]; $table_files="files"; $results=$DB->get_records($table_files,array('filename'=>$course_name)); //Get the file details here:::: foreach($results as $obj){ $contextid=$obj->contextid; $component=$obj->component; $filearea=$obj->filearea; $itemid=$obj->itemid; } $url=$CFG->wwwroot/pluginfile.php/$contextid/$component/$filearea/$itemid/$course_name; echo print_r($url); ?> Will appreciate the help.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base