I have a small custom module that updates a table with a uid and fid every time a user downloads a file. I now need to export this information to Salesforce using a "CampaignID" associated with the file.

I've managed everything except for getting the CampaignIDs. The approach I've taken is to add a CCK field to the node type with the downloads (files are only uploaded once, but admins, otherwise I realize this wouldn't work). Now I need to get the nid of the node the user is downloading from so I can load it and grab the CampaignID.

The only way I see to get the nid is to
*SELECT fid FROM {files} WHERE filename = '%s', $filename
*SELECT nid FROM {uploads} WHERE fid = '%d', $fid

I feel like there should be an easier way, since the module is being called by the node, right? Am I missing something, or are SQL calls the only way to get at this?

Thanks,
M

ps -- alternative suggestions for a way to accomplishing my goal also welcome

Comments

vali hutchison’s picture

If this is an file attached through a file or image field, you can instead implement hook_file_download_access(), which gives you the $field, $entity_type and $entity to which the file belongs.