PDA

View Full Version : Way to get attachment url in header?


tpearl5
02-16-2012, 11:14 PM
I'm looking for a way to say....

If first attachment is an image, url

...in the headerinclude template.

Any ideas?

Lynne
02-17-2012, 01:09 AM
I'm not sure I understand. How do you define the first attachment? Do you mean the first one used in the post? If so, you'd have to search for "[attach]" or "[attach=config]" in there and find the attachment id and then find out it's extension.

tpearl5
02-17-2012, 01:13 AM
I guess it would be 'if an attachment in first post is an image'

Lynne
02-17-2012, 01:23 AM
That is going to require a query done right off the bat since attachments aren't looked at at the time the header is rendered. You have the threadid at that point, but that is all. So, you'd need to do a query on the thread table to get the first postid and join with the filedata (maybe attachment - I'm not looking at a database right now) table and then take a look at the extension.

tpearl5
02-17-2012, 01:52 AM
hrm, so it would be something like this?

SELECT attachmentid FROM attachment WHERE postid = $post[postid] ORDER BY attachmentid LIMIT 1

Lynne
02-17-2012, 04:45 PM
There is no postid field in the attachment table. It would need to be something more like:

SELECT attachmentid FROM attachment WHERE contenttypeid=1 AND contentid= $post[postid] ORDER BY attachmentid LIMIT 1

(not tested at all)

tpearl5
02-18-2012, 05:46 PM
oh okay - so then it would just be a matter of writing something to cache that in a database table so a query isn't run every time a page is loaded.

Lynne
02-18-2012, 05:59 PM
I guess if I were going to do this, I would maybe add another field to the thread table. If that field is empty, then you run that query and then run another one to enter the attachmentid into the new field. That way, the two queries only get run the first time someone accesses the thread. You may need to do something for when someone edits the thread and changes attachments though.

tpearl5
02-19-2012, 05:00 PM
Thanks for the tips Lynne. Btw, this is the reason I'm trying to figure out how to do this:
https://vborg.vbsupport.ru/showthread.php?t=275236

It doesn't make sense that the image for facebook is static.

Anatoliy2
05-31-2012, 02:41 PM
SELECT attachmentid FROM attachment WHERE contenttypeid=1 AND contentid= $post[postid] ORDER BY attachmentid LIMIT 1

So when my php scrypt got an attachmentid (in my case it's 24561) what the path to the image would be (so the script would display the image)? I see 'filename' - 1.jpg (the original name of the picture). What is the path to it?

Lynne
05-31-2012, 02:53 PM
You may look into the function fetch_attachment_path