Modify Attachment upload behavior

Started by Boskonovic, August 16, 2011, 11:29:47 AM

Previous topic - Next topic

Boskonovic

Hi!

I need some tips to implement a new feature regarding attachments and .sc2replay files( Replays from Blizzard's game Starcraft 2).
Smf 2.0

What I want to do is:

-Let people uploading .sc2replay files and select a checkbox in the attachment section if they want those replays to be parsed(to retrieve specific infos from the replay data);
-Verify if the uploaded file extensione is ".sc2replay" and if the checkbox for the parsing operation has been checked;
-Send the file to a script which will parse it, to get the infos I need; -> Script already written
-Append those infos to the Post message(at the end of it, inside a spoiler tag, for example);

So, guide me:
1)In Post.Template.php, i should add the checkbox(with its name and id):
// Is the user allowed to post any additional ones? If so give them the boxes to do it!
if ($context['can_post_attachment'])
{
echo '
<dl id="postAttachment2">
<dt>
', $txt['attach'], ':
</dt>
<dd class="smalltext">
<input type="file" size="60" name="attachment[]" id="attachment1" class="input_file" /><label for="check_parse"><input type="checkbox" class="input_check" value="1" id="check_parse" name="parse"> Parse the file(only if it's .sc2replay)</label> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';



2)In Post.php, for every attachment, it should be checked if the "parse" box has been selected:
$context['parse'] = !empty($_REQUEST['parse']);
And if the file extension is .sc2replay:
$ext = strtolower(substr(strrchr($_FILES['attachment']['name'][$n], '.'), 1))

3)If both values are ok, the file can be parsed and the infos retrieved can be merged with the post message, which should be:
$_POST['message'](first lines of Post2() function)

It should work or there is any error?

The cycle through the attachments uploaded, is done inside this foreach, in Post.php?
foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
{
if ($_FILES['attachment']['name'][$n] == '')
continue;


If yes, can I work there, editing the code to add point 2) checks and point 3) operations?

Or elsewhere?

Thank you for your help!

Bye

Advertisement: