XF 1.5 How to locate an attachment with the attachment ID?

Ludachris

Well-known member
I have a reported thread where the attachments are showing up as hyperlinked text like this: View Attachment 104607

The bbcode used in the post is
Code:
[ATTACH=full]104607[/ATTACH]

My question is, how do I search for that attachment in the system to get the actual URL for the attachment to fix the post manually?
 
The actual url is https://<domain>/<forumroot>/attachments/104607, but I doubt this will help you
Yeah, that is the URL that the hyperlink points to, which is broken. When I look at other attachments in the attachment browser in ACP, they have the file name in the URL, along with an ID. Is there a way to find the attachment in the ACP with the ID?
 
The file name isn't really relevant, you can put anything there.

Try this: https://xenforo.com/community/attachments/this-is-fake.exe.218495

If the ID does not work you've got an inconsistent/damaged DB or filesystem, fixing this (and recovering the attachment if possible) most likely requires expert knowledge.
 
The file name isn't really relevant, you can put anything there.

Try this: https://xenforo.com/community/attachments/this-is-fake.exe.218495

If the ID does not work you've got an inconsistent/damaged DB or filesystem, fixing this (and recovering the attachment if possible) most likely requires expert knowledge.
Okay, so again, is there a way to search the attachment ID anywhere to try and locate the file?
 
I doubt it will get you anywhere ...

Use the tool of your choice (PMA, Adminer, Heidi, etc.) and search the ID in field attachment_id of table xf_attachment.
If you are lucky and the record does exist note down the value of field data_id.
If it does not exist try to guess the value by looking at rows with slightly higer and lower attachment_id.

Now go to table xf_attachment_data and locate the record by searching for the data ID in field data_id, note down the value of fields file_hash and filename.

When you got the data_id, divide it by 1000, truncate the decimals and note down that number .

Afterwards go to directory (via SFTP or whatever) /path/to/forumroot/internal_data/attachments/<number> and try to locate file <dataid>-<hash>.data.
If this file does exist, this is most likely the attachment you are searching.
 
I doubt it will get you anywhere ...

Use the tool of your choice (PMA, Adminer, Heidi, etc.) and search the ID in field attachment_id of table xf_attachment.
If you are lucky and the record does exist note down the value of field data_id.
If it does not exist try to guess the value by looking at rows with slightly higer and lower attachment_id.

Now go to table xf_attachment_data and locate the record by searching for the data ID in field data_id, note down the value of fields file_hash and filename.

When you got the data_id, divide it by 1000, truncate the decimals and note down that number .

Afterwards go to directory (via SFTP or whatever) /path/to/forumroot/internal_data/attachments/<number> and try to locate file <dataid>-<hash>.data.
If this file does exist, this is most likely the attachment you are searching.
Thanks @Kirby - I found the file in the db and the file system using this method. I wonder why it's not displaying when I access the attachment's URL.
 
If you can provide the link to the post and the absolute URL to the attachment then we may be able to provide some insight.
Here's the post:

The URL of the attachment is here:
/public_html/internal_data/attachments/104/104607-e8892842d401ae0f139ad2e28b6bf059.data

In the DB, the file name is specified as IMAG0553.jpg
 
When I try to access this file:

https://www.dsmtuners.com/internal_data/attachments/104/104607-e8892842d401ae0f139ad2e28b6bf059.data

I get the following error message:

1584057932316.webp
 
I think we may need to come back to the initial question.

An attachment will only appear embedded within a post if the attachment is actually attached to that post. If you reference an attachment that is associated with some other content, we won't display it; we'll just display a placeholder like that. So the only way to fix this would be to reupload the attachment to the post in question.

In this example, clicking the attachment in question gives an attachment not found error. This would generally indicate that the attachment has actually been deleted. If the attachment was not viewable, in this case, it should give a no permission error.

In terms of identifying an attachment, the ID referenced is the attachment ID in xf_attachment, not the data_id used by xf_attachment_data. They may be the same in many cases, but that can't be guaranteed. I presume if you look in the xf_attachment table for this attachment, you won't find it.
 
I think we may need to come back to the initial question.

An attachment will only appear embedded within a post if the attachment is actually attached to that post. If you reference an attachment that is associated with some other content, we won't display it; we'll just display a placeholder like that. So the only way to fix this would be to reupload the attachment to the post in question.

In this example, clicking the attachment in question gives an attachment not found error. This would generally indicate that the attachment has actually been deleted. If the attachment was not viewable, in this case, it should give a no permission error.

In terms of identifying an attachment, the ID referenced is the attachment ID in xf_attachment, not the data_id used by xf_attachment_data. They may be the same in many cases, but that can't be guaranteed. I presume if you look in the xf_attachment table for this attachment, you won't find it.
That's the thing, I did find it in the attachment table, I even mentioned the name of the file above. I found the file in the file system. If it's in the db and in the file system, that means it's not deleted, correct? I should be able to change the bbcode to IMG and reference the attachment that way, right?

It appears that all other attachments use the file name in the URL. If I try and guess the URL based on the strings of other attachments (/attachments/file-name-jpg.104607/) it doesn't work.
 
It appears that all other attachments use the file name in the URL. If I try and guess the URL based on the strings of other attachments (/attachments/file-name-jpg.104607/) it doesn't work.
As posted before, the "filename" in the URL is irelevant.

If the DB entries are there and the file is there as well you'll have to dig deeper.

Did you explain the queries and tried to execute them manually to verify the results?
Is the file accessible for the user executing the PHP files?
 
That's the thing, I did find it in the attachment table, I even mentioned the name of the file above. I found the file in the file system. If it's in the db and in the file system, that means it's not deleted, correct?
The file you found and the filename you mentioned come from the xf_attachment_data table, not the xf_attachment table. You need to look up the attachment record:
Code:
SELECT * FROM xf_attachment WHERE attachment_id = 104607;

I presume that won't return anything.
 
The file you found and the filename you mentioned come from the xf_attachment_data table, not the xf_attachment table. You need to look up the attachment record:
Code:
SELECT * FROM xf_attachment WHERE attachment_id = 104607;

I presume that won't return anything.
Yup, you're right, it's not in there. I was looking in the wrong table. So just so I understand, how would the attachment get removed from that table and not the other locations? Is that common when an attachment gets deleted? Or would it be evidence that something went wrong with an import?
 
104607 is the attachment_id

You need to look at the xf_attachment table and search for that attachment_id. Once located you will then need to get the data_id which is more than likely a different number. Once you have the data_id you can then look for the file:

internal_data/attachments/{first three numbers of the data_id}/{data_id}-{hash}.data
 
Top Bottom