Image getting delete away by the cronjob later in drupal 7 using theme settings i`m using system theme settings alter to add 4 images for theme, images are getting deleted /swept away by the cronjob later .trying using  FILE_STATUS_PERMANENT images are not getting set as permanent

   function themeA_form_system_theme_settings_alter(&amp;$form, &amp;$form_state) {

  $form['themeA_settings']['header-page']['header_background_file'] = array(
    '#type' =&gt; 'managed_file',
    '#title' =&gt; t('Header Background'),
    '#required' =&gt; FALSE,
    '#upload_location' =&gt; file_default_scheme() . '://themebackrounds/',
    '#default_value' =&gt; theme_get_setting('header_background_file'),
    '#upload_validators' =&gt; array(
        'file_validate_extensions' =&gt; array('gif png jpg jpeg'),
    ),
  '#submit' =&gt; array('themeA_submit_handler'),
  );


  $form['themeA_settings']['block1']['block1_file'] = array(
    '#type' =&gt; 'managed_file',
    '#title' =&gt; t('block1 image'),
    '#required' =&gt; FALSE,
    '#upload_location' =&gt; file_default_scheme() . '://themebackrounds/',
    '#default_value' =&gt; theme_get_setting('block1_file'),
    '#upload_validators' =&gt; array(
        'file_validate_extensions' =&gt; array('gif png jpg jpeg'),
    ),
  '#submit' =&gt; array('themeA_submit_handler'),
  );



 $form['themeA_settings']['block2']['block2_file'] = array(
    '#type' =&gt; 'managed_file',
    '#title' =&gt; t('block2 image'),
    '#required' =&gt; FALSE,
    '#upload_location' =&gt; file_default_scheme() . '://themebackrounds/',
    '#default_value' =&gt; theme_get_setting('block2_file'),
    '#upload_validators' =&gt; array(
        'file_validate_extensions' =&gt; array('gif png jpg jpeg'),
    ),
'#submit' =&gt; array('themeA_submit_handler'),
);



$form['themeA_settings']['footer']['background_file'] = array(
    '#type' =&gt; 'managed_file',
    '#title' =&gt; t('Footer Background'),
    '#required' =&gt; FALSE,
    '#upload_location' =&gt; file_default_scheme() . '://themebackrounds/',
    '#default_value' =&gt; theme_get_setting('background_file'),
    '#upload_validators' =&gt; array(
        'file_validate_extensions' =&gt; array('gif png jpg jpeg'),
    ),
 '#submit' =&gt; array('themeA_submit_handler'),
  );



  }
   function themeA_submit_handler($form, &amp;$form_state) {
        // Load the file via file.fid.
     if (isset($form_state ['values']['header_background_file'])) {
     $file = file_load($form_state['values']['header_background_file']);
          }
     if (isset($form_state ['values']['block1_file'])) {
       $file = file_load($form_state['values']['block1_file']);
           }
       if (isset($form_state ['values']['block2_file'])) {
          $file = file_load($form_state['values']['block2_file']);
        }
      if (isset($form_state ['values']['background_file'])) {
       $file = file_load($form_state['values']['background_file']);
     }
           // Change status to permanent.
           $file-&gt;status = FILE_STATUS_PERMANENT;
          // Save.
        file_save($file);
          // Record that the module (in this example, user module) is using the file. 
        file_usage_add($file, 'user', 'user', $account-&gt;uid);  
     }
A quote from the docs:


  Note: New files are uploaded with a status of 0 and are treated as temporary files which are removed after 6 hours via cron. Your module is responsible for changing the $file objects status to FILE_STATUS_PERMANENT and saving the new status to the database. Something like the following within your submit handler should do the trick ...


You would need to put the example code that follows in the docs, into a function that you add as a submit handler:

$form['themeA_settings']['header-page']['header_background_file'] = array(
  '#type' =&gt; 'managed_file',
  ...
  '#submit' =&gt; array('your_custom_submit_handler'), // &lt;-- This line is new
);


The function itself could look like this then:

function your_custom_submit_handler($form, &amp;$form_state) {
  // Load the file via file.fid.
  $file = file_load($form_state['values']['my_file_field']);
  // Change status to permanent.
  $file-&gt;status = FILE_STATUS_PERMANENT;
  // Save.
  file_save($file);
  // Record that the module (in this example, user module) is using the file. 
  file_usage_add($file, 'user', 'user', $account-&gt;uid);  
}


You can of course reuse that function for all your files.