Why does my file get removed after six hours?
My managed image got removed after a certain amount of time. How did that happen? After searching a bit I figure out.
The Form API has a form element called managed_file. It uploads a file and adds it to the managed files table. This way Drupal has knowledge about and control over it. But now I got the situation that after a certain amount of time the image got removed. It just disappeared. What is happening here?
Well the managed_file works with Ajax. To smooth the proces it adds the managed file and leaves the status on temporary until some one specifies 'this is my file its managed'. You do that by adding this snippet of code to your submit handler.
$file = file_load($form_state['values']['file_element_name']); <br><br>// Change status to permanent. <br>$file->status = FILE_STATUS_PERMANENT; <br><br>// Save. <br>file_save($file);
If you have your form managed by
system_settings_form()
you want to add a extra submit handler. You can do that this way.
$form['#submit'][] = 'extra_admin_submit';