I added such code in my custom theme:
// Background image setting.
$name = 'theme_custom/backgroundimage2';
$title = 'backgroundimage2';
$description = 'backgroundimage_desc';
$setting = new admin_setting_configstoredfile($name, $title, $description, 'backgroundimage2');
Setting seems like OK, I can upload an image, the image is visible under settings tab, but when I try to echo this image using such code
it shows such url //mydomainname.com/pluginfile.php/1/theme_custom/backgroundimage2/-1/test.jpg
which points to the not found file.