No announcement yet.

Safest way to cleanup Upload folder

  • Filter
  • Time
  • Show
Clear All
new posts

  • Safest way to cleanup Upload folder

    Hello guys, back in the days I needed to make some free space on our hosting.

    So I just selected attachments older than X days in our SQL table "attachments" then took the list of IDs and then deleted these IDs from the upload directory using my php script.

    The problem is that the system started generating errors connected with attachments

    [2023-05-29 04:32:41] ERROR: (403) GET /; line: 69, file: /data/0/f/0f6e82d6-07b5-42f8-803a-fad2758ce077/ [] []
    [2023-05-29 04:32:41] ERROR: (403) GET /; line: 69, file: /data/0/f/0f6e82d6-07b5-42f8-803a-fad2758ce077/ [] []​
    I would like to ask you what is the safest way to delete these attachments to avoid errors afterward? I was thinking about instead of deleting it directly from the upload I could just change "deleted" in the SQL table to 1 and then run hard rebuild. Would it do the magic, please?

    Thanks a lot for the tips.

  • #2
    1. In Administration > Attachments filter the necessary files and delete them.
    2. Only then clean the deleted files in the database.

    It's generally not recommended to delete anything from the database before that data has been deleted from the UI.
    If I were you, I would back up and follow these 2 steps to avoid errors related to attachments.​
    Last edited by victor; 07-03-2023, 01:37 PM.


    • Jakub Grufik
      Jakub Grufik commented
      Editing a comment
      will do, thanks a lot!

  • #3
    victor please sir, how long does it take for the files to be removed from the upload directory to free up some space on the hosting after deleting them in the Administration -> Attachments? Or what else needs to be done to delete those files immediately from the upload directory, please?

    Thank you


    • victor
      victor commented
      Editing a comment
      I deleted in PHPMyAdmin a minute after I deleted in the UI - I didn't notice any problems or errors. However, it is worth noting that on the test instance I did not have any formulas or workflows that were somehow related to Attachments. In more detail, my experiment looked like this:
      - Created a field for attachments in the Meeting entity.
      - Uploaded a file to this field.
      - Deleted this file in Administration > Attachments.
      - The file was deleted from the file field of my test meeting (on its own).
      - Went to PHPMyAdmin > Attachments > found this file in the Deleted column > Deleted it from PHPMyAdmin.
      - Made a Hard Rebuild.
      - In the future, I did not receive any errors.