Files in the file_managed table with status of 0, not deleting on cron I have a form where I am uploading files to the "sites/default/files" directory. I am using the managed_file type in my form API definition. This is all working fine and I notice that in the file_managed table, I see my uploaded files with a status of 0 meaning they are temporary. I was under the impression that these files that have a status of 0 should get deleted, not only from the database, but physically from the server on cron run, but I do not see this happening. I see lots of files with a status of 0 and they are NOT in the file_usage table, so they are not being used by anything, yet if I force a cron run, I don't get errors, yet the files do not get deleted either. Am I misunderstanding how this system works?

Thanks
They are deleted, but during cron tasks, and just when:


They aren't marked as permanent
They are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE seconds
No module contains a reference to those files


The code that deletes those temporary files is contained in system_cron(). 

  // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
  // Use separate placeholders for the status to avoid a bug in some versions
  // of PHP. See http://drupal.org/node/352956.
  $result = db_query('SELECT fid FROM {file_managed} WHERE status &lt;&gt; :permanent AND timestamp &lt; :timestamp', array(
    ':permanent' =&gt; FILE_STATUS_PERMANENT,
    ':timestamp' =&gt; REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
  ));
  foreach ($result as $row) {
    if ($file = file_load($row-&gt;fid)) {
      $references = file_usage_list($file);
      if (empty($references)) {
        if (!file_delete($file)) {
          watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' =&gt; $file-&gt;uri), WATCHDOG_ERROR);
        }
      }
      else {
        watchdog('file system', 'Did not delete temporary file "%path" during garbage collection, because it is in use by the following modules: %modules.', array('%path' =&gt; $file-&gt;uri, '%modules' =&gt; implode(', ', array_keys($references))), WATCHDOG_INFO);
      }
    }
  }


If the files are not getting deleted, and you don't see any error message in the watchdog log database, then you need to check cron tasks are executed and the files are older than 6 hours. In the other cases, you should get an entry in the watchdog database table, even if that would be a generic Could not delete temporary file.