$file_path = '/module1/documents/example.pdf'; $context = context_module::instance($module_id); $plugin_file_url = moodle_url::make_pluginfile_url($context->id, $context->component, $context->contextlevel, $context->instanceid, $file_path);
$file_path = '/myfolder/image.jpg'; $context = context_user::instance($user_id); $plugin_file_url = moodle_url::make_pluginfile_url($context->id, 'user', CONTEXT_USER, $user_id, $file_path);This code generates a URL to an image file stored in a custom folder named "myfolder". The context of the file is a user profile, identified by its $user_id variable. This time, the resulting URL includes the user's token, which allows the file to be accessed without requiring login again. Package/Library name: Moodle Core Library