I am trying to create functionality where administrator can upload header image whenever he wants.
hook_form_system_theme_settings_alter in theme-settings.php and altering form like this:
$form['theme_settings']['background_file'] = array( '#type' => 'managed_file', '#title' => t('Background'), '#required' => TRUE, '#upload_location' => file_default_scheme() . '://public/backgrounds/', '#default_value' => theme_get_setting('background_file'), '#upload_validators' => array( 'file_validate_extensions' => array('gif png jpg jpeg'), ), );
template.php using hook_preprocess_page and doing this in it:
$fid = theme_get_setting('background_file'); $loaded = file_load($fid); $variables['background_url'] = file_create_url($loaded->uri);
and trying to reach
$variables['background_url'] from tpl.php file.
When I upload image everything works great, header image is set properly and code has no problem but after a while, I don't really know what happens, for example after 1 day file_load returns
FALSE, I just reupload image and everything works fine again.
theme_get_setting('background_file'); always returns file id without problems.
I am missing something? I can't find source of problem.