News:

Wondering if this will always be free?  See why free is better.

Main Menu

clean-out orphaned files from attachment folder

Started by RoyceMcKnight, July 14, 2008, 06:28:43 PM

Previous topic - Next topic

RoyceMcKnight

Heyho, I've searched the forums for half an hour, but could not find anything, so please forgive me if theres already a thread offering a solution to my problem.

My problem is: There are still files left in my attachment folder which already got deleted in my forum. I don't know how this has happend, particularly as it isn't happening anymore. Now when I delete an attachment from the forum, the file in the attchment folder gets deleted as well.

But I did some checking, and there are orphaned files in the attachment folder which have no corresponding entry in the database. So my question is: is there any way, maybe a little script, that could check my attachment folder for files which have no corresponding database entry and list them. Normally I would do this by hand, but with over 2.000 attachments this could take some time :-)
I use encrypted filenames.

I already used the attachment maintenance, but it does not incorporate checking for orphaned file leftovers.

Greetings from germany, Mike

kat

It's not what you asked for, but wouldn't the "Remove attachments older than x days" do a close job to what you want?

RoyceMcKnight

Hm no, this function would only remove active attachments from my forum, but not the orphaned files in the attachment folder. But I don't want any active attachment to be pruned out, they're all usefull :-)

kat

Right. Yeah, I can see your problem.

Not a clue, myself. I'll keep an eye on this thread, though, to see if there IS a way.

Might help me out, too! :)

greyknight17

Go to Admin->Attachments and Avatars->File Maintenance and click on the Maintain link. See if that helps resolve the issue.

RoyceMcKnight

Quote from: greyknight17 on July 19, 2008, 12:49:59 AM
Go to Admin->Attachments and Avatars->File Maintenance and click on the Maintain link. See if that helps resolve the issue.

Quote from: RoyceMcKnight on July 14, 2008, 06:28:43 PM
I already used the attachment maintenance, but it does not incorporate checking for orphaned file leftovers.

I already tried that with no success :-)

Rumbaar

Well that's a tough one, and I don't think it's possible. Due to the md5 hash assigned to a file name once it's saved and unique attachment ID.

Now you'll need to do a loop scan of the directory, removing the last 32 digits (md5 hash) and the first prefix attach ID number from the file (which can be variable so not sure how to get that one, maybe preg_replace from the ending _ of the ID?).  Ideally would like to use the function getAttachmentFilename() to get the clean file name, but without the original file name or attachment ID we can't use that function to remove the ID and/or md5 hash.

Then loop through the attachment table to compare and see if that filename is not longer referenced.  Now you run into issues with the fact you can use the same name more than once when file encryption is turned on.  So you can still get false positives.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

kat

The only other manual way I can think of, is to delete them, using your ftp-client, looking at the datestamp on the file.

Bit long-winded, though, and not terribly accurate.

Rumbaar

Datestamp will not indicate if it's still attached or an actual message or not though.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

kat

No, of course not.

That's what I meant by "Not terribly accurate".

Rumbaar

Yeah sorry to say currently no automated or easy way to do it.  It is strange that when the post was deleted it didn't remove the attachments in the first place.

I'd say [Mod] Request, but I can't see a way to do it with any certainty.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

Advertisement: