Update:
After digging around a bit I kept the way of accessing the database, even though I would love to not do this. Instead of doing the query myself, I now use the finder:
With the Data-Id I have everyting I need for this solution. Since I know the Attachment-Storage-Logic I can string the actual path together.
Will keep it that way for now but better solutions are still welcome.
______________________________________________________
Orginal post:
Hello everyone,
I'm trying to implement a file-parser for attachments but I struggle with getting the actual files.
The idea is, given you have an application where you can create recipes, you export them and share by uploading them as an attachment. If someone likes the recipe he/she downloads them and imports them in their application.
But I don't want them to need to download it first, so instead of the default XF attachment thumbnail I want to write a little preview, showing the recipes infos. I also don't mind if someone may read it without being registered since they still won't be able to download it.
Sloppy Example:
For that I edit the attachment_macros template and add a callback which should parse the file identified by its extension.
The callback works, I end up in my addons php and receive the param I hand over from the template. The problem now is, I cannot do anything with it because I cannot access the actual file. I already tried to access the file by using curl and the attachments url. This fails since I then get the error I am not logged in and some really messy iframe like pages. But at the end of the day I don't like this solution anyways since the real file is just a few folders away. I also learned I get the data_id and the attachment_id so I might end up calling the database and getting the hash to then build the path on my own. But this would be a bad solution as well.
Template Extension:
getData-Method which leads to an embedded login-form:
Long story short, does anyone know how to access the actual file stored in the internal_data from an attachment?
Thanks in advance!
After digging around a bit I kept the way of accessing the database, even though I would love to not do this. Instead of doing the query myself, I now use the finder:
Code:
$finder = \XF::finder('XF:Attachment');
$attachment = $finder->where('data_id', $dataId)->fetchOne();
$attachmentHash = $attachment->Data->file_hash;
Will keep it that way for now but better solutions are still welcome.
______________________________________________________
Orginal post:
Hello everyone,
I'm trying to implement a file-parser for attachments but I struggle with getting the actual files.
The idea is, given you have an application where you can create recipes, you export them and share by uploading them as an attachment. If someone likes the recipe he/she downloads them and imports them in their application.
But I don't want them to need to download it first, so instead of the default XF attachment thumbnail I want to write a little preview, showing the recipes infos. I also don't mind if someone may read it without being registered since they still won't be able to download it.
Sloppy Example:
For that I edit the attachment_macros template and add a callback which should parse the file identified by its extension.
The callback works, I end up in my addons php and receive the param I hand over from the template. The problem now is, I cannot do anything with it because I cannot access the actual file. I already tried to access the file by using curl and the attachments url. This fails since I then get the error I am not logged in and some really messy iframe like pages. But at the end of the day I don't like this solution anyways since the real file is just a few folders away. I also learned I get the data_id and the attachment_id so I might end up calling the database and getting the hash to then build the path on my own. But this would be a bad solution as well.
Template Extension:
Code:
<xf:callback class="TEST\\RecipeParser" method="getData" params="[]">{{ link('full:attachments', $attachment) }}</xf:callback>
getData-Method which leads to an embedded login-form:
Code:
public static function getData($recipePath){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $recipePath);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
return 'TODO';
}
Long story short, does anyone know how to access the actual file stored in the internal_data from an attachment?
Thanks in advance!
Last edited: