Skip to main content

Deleting File Attachments with Drupal's node_save() Function

Today I ran into an issue of needing to programmatically remove file attachments from a node. To accomplish this I referred to the upload_nodeapi() function and found the upload_save() function. After examining the code I found that upload_save looks for the 'remove' parameter for the file object. If $file->remove exists, the file will be deleted from the database and file system. So by adding the 'remove' parameter to the files I needed removed before calling node_save() results in the files being removed from the node upon calling node_save(). Done!


Comments