When a node is updated by replacing a new file upload, old files exist on the server maintaining versions.I want delete old files from server when content is updated in Drupal7


This is already discussed topic. I found some source.

Drupal Forum and Original Source

After that I would create a cron job (Implementing hook_cron). And insert this snippet.

I hope it works out for you.

Alternatively, if you dont want this action to happen once per day, you can insert it in hook_submit, or hook_update. But I would go for the first method.

Do it once per day/week/whatever time period you like.

| improve this answer | |
  • Thanks for the solution @Oleg Videnov, I put the code snippet in hook_cron in my custom module.It deletes all the file that are not attached to any node.But next thing that has to be done is file name is getting changed like it appends filename_0.pdf, I want the same name e.g. filename.pdf – Astha chauhan Oct 22 '13 at 9:47
  • Can you try to flush your cache before this action ? – Oleg Videnov Oct 22 '13 at 10:56
  • No result. @Oleg Videnov – Astha chauhan Oct 22 '13 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.