<?php
[/size][/color]
define("IN_MYBB", 1);
define('NO_ONLINE', 1);
define('THIS_SCRIPT', 'upload.php');
require_once "./global.php";
// Load global language phrases
$lang->load("newreply");
$fid = $mybb->input['fid'];
$pid = intval($mybb->input['pid']);
$tid = intval($mybb->input['tid']);
$thread = get_thread($tid);
// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}
$forumpermissions = forum_permissions($fid);
if($forum['open'] == 0 || $forum['type'] != "f")
{
error($lang->error_closedinvalidforum);
}
if($forumpermissions['canview'] == 0 || ($forumpermissions['canpostreplys'] == 0 && $pid) || $mybb->user['suspendposting'] == 1)
{
error_no_permission();
}
if($forumpermissions['canonlyviewthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
{
error_no_permission();
}
// Check if this forum is password protected and we have a valid password
check_forum_password($forum['fid']);
// Check to see if the thread is closed, and if the user is a mod.
if(!is_moderator($fid, "caneditposts"))
{
if($thread['closed'] == 1)
{
error($lang->redirect_threadclosed);
}
}
if($pid != 0)
{
$attachwhere = "pid=".$pid;
}
else
{
$attachwhere = "posthash='".$db->escape_string($mybb->input['posthash'])."'";
}
$query = $db->simple_select("attachments", "COUNT(aid) as numattachs", $attachwhere);
$attachcount = $db->fetch_field($query, "numattachs");
$is_error = false;
foreach($_FILES as $key => $file)
{
if($file['size'] == 0)
{
continue;
}
$i = str_replace('attachment', '', $key);
// If there's an attachment, check it and upload it
if($file['size'] > 0 && $forumpermissions['canpostattachments'] != 0 && ($mybb->settings['maxattachments'] == 0 || $attachcount < $mybb->settings['maxattachments']))
{
require_once MYBB_ROOT."inc/functions_upload.php";
$attachedfile = upload_attachment($file, false);
}
if($attachedfile['error'])
{
$error = 'error'.$i;
if($file['name'])
{
$attachedfile['error'] = $file['name'].': '.$attachedfile['error'];
}
$$error = '<br />'.$attachedfile['error'];
$is_error = true;
}
else
{
$attachcount++;
}
}
if($forumpermissions['canpostattachments'] != 0 && $mybb->input['action'] == 'list')
{ // Get a listing of the current attachments, if there are any
$attachcount = 0;
if($mybb->input['action'] == "editdraft" || ($mybb->input['tid'] && $mybb->input['pid']))
{
$attachwhere = "pid=".$pid;
}
else
{
$attachwhere = "posthash='".$db->escape_string($mybb->input['posthash'])."'";
}
$query = $db->simple_select("attachments", "*", $attachwhere);
$attachments = '';
while($attachment = $db->fetch_array($query))
{
$attachment['size'] = get_friendly_size($attachment['filesize']);
$attachment['icon'] = get_attachment_icon(get_extension($attachment['filename']));
if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0))
{
eval("\$postinsert = \"".$templates->get("post_attachments_attachment_postinsert")."\";");
}
$attach_mod_options = '';
if($attachment['visible'] != 1)
{
eval("\$attachments .= \"".$templates->get("post_attachments_attachment_unapproved")."\";");
}
else
{
eval("\$attachments .= \"".$templates->get("post_attachments_attachment")."\";");
}
$attachcount++;
}
$query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
$usage = $db->fetch_array($query);
if($usage['ausage'] > ($mybb->usergroup['attachquota']*1024) && $mybb->usergroup['attachquota'] != 0)
{
$noshowattach = 1;
}
if($mybb->usergroup['attachquota'] == 0)
{
$friendlyquota = $lang->unlimited;
}
else
{
$friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);
}
$friendlyusage = get_friendly_size($usage['ausage']);
$lang->attach_quota = $lang->sprintf($lang->attach_quota, $friendlyusage, $friendlyquota);
if($mybb->settings['maxattachments'] == 0 || ($mybb->settings['maxattachments'] != 0 && $attachcount < $mybb->settings['maxattachments']) && !$noshowattach)
{
eval("\$newattach = \"".$templates->get("post_attachments_new")."\";");
}
eval("\$attachbox = \"".$templates->get("post_attachments")."\";");
output_page($attachbox);
}
else
{
if($mybb->request_method == 'post')
{
$add = '';
if(!$is_error)
{
$add = ' window.close();';
}
$update = "<script type=\"text/javascript\">
new Ajax.Request('upload.php?posthash={$mybb->input['posthash']}&my_post_key={$mybb->post_code}&fid={$fid}&pid={$mybb->input['pid']}&action=list', {method: 'get', onComplete: function(request) { opener.document.getElementById('attachment_table').innerHTML = request.responseText;{$add} }});
</script>";
}
eval("\$add = \"".$templates->get("post_attachments_add")."\";");
output_page($add);
}
?>
[color=#333333][size=small]