Files getting deleted from sites/default/files
gopikn - May 15, 2009 - 20:43
Hi,
I created a custom module which has a form and option for file upload in it. I am using a contributed module called "upload_element" for uploading files on the form. I am able to do the same sucessfully and able to view it. The files are uploaded to the folder "sites/default/files" location. My problem is..overnight, the file are getting deleted from the server. I first doubt it was something to do with cron job. But when I run the cron job manually, it is not deleting the files. So, I suppose, it is not with cron job.
Any thoughts on this ?.. Any suggestions welcome.

Are you saving the upload in the submit handler?
The module uploads all files as temp. files, and it is up to you what you do with them. Temp files older than a day or so are deleted during cron processing.
The save function supplied with the module will move these into the supplied files directory and mark the file as a permanent file. It is not automatically added as a submit handler to the element to allow greater flexibility with the module.
For example, it can be used on new nodes and you can save these into a location based on the inserted node id.
Eg: From a node based form.
<?php/**
* Implementation of hook_insert().
*/
function airline_insert($node) {
// Save the image in the form field "fid" into the directory "logos/[node nid], replacing any existing file - FILE_EXISTS_RENAME can force the file to be renamed if there is a conflict.
$fid = upload_element_save($node->fid, 'logos/'. $node->nid, FILE_EXISTS_REPLACE);
// Save the file id returned from the save handler (0 if no file is present) if required
}
?>
Hope this helps - it would have been a nasty surprise having random images getting deleted!
Alan Davison
www.caignwebs.com.au