本文整理汇总了PHP中upload_attachment函数的典型用法代码示例。如果您正苦于以下问题:PHP upload_attachment函数的具体用法?PHP upload_attachment怎么用?PHP upload_attachment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了upload_attachment函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload_attach_func
function upload_attach_func($xmlrpc_params)
{
global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups;
$lang->load("member");
$parser = new postParser();
$input = Tapatalk_Input::filterXmlInput(array('forum_id' => Tapatalk_Input::INT, 'group_id' => Tapatalk_Input::STRING, 'content' => Tapatalk_Input::STRING), $xmlrpc_params);
$fid = $input['forum_id'];
//return xmlrespfalse(print_r($_FILES, true));
// Fetch forum information.
$forum = get_forum($fid);
if (!$forum) {
return xmlrespfalse($lang->error_invalidforum);
}
$forumpermissions = forum_permissions($fid);
if ($forum['open'] == 0 || $forum['type'] != "f") {
return xmlrespfalse($lang->error_closedinvalidforum);
}
if ($mybb->user['uid'] < 1 || $forumpermissions['canview'] == 0 || $forumpermissions['canpostthreads'] == 0 || $mybb->user['suspendposting'] == 1) {
return tt_no_permission();
}
// Check if this forum is password protected and we have a valid password
tt_check_forum_password($forum['fid']);
$posthash = $input['group_id'];
if (empty($posthash)) {
$posthash = md5($mybb->user['uid'] . random_str());
}
$mybb->input['posthash'] = $posthash;
if (!empty($mybb->input['pid'])) {
$attachwhere = "pid='{$mybb->input['pid']}'";
} else {
$attachwhere = "posthash='{$posthash}'";
}
$query = $db->simple_select("attachments", "COUNT(aid) as numattachs", $attachwhere);
$attachcount = $db->fetch_field($query, "numattachs");
//if(is_array($_FILES['attachment']['name'])){
foreach ($_FILES['attachment'] as $k => $v) {
if (is_array($_FILES['attachment'][$k])) {
$_FILES['attachment'][$k] = $_FILES['attachment'][$k][0];
}
}
//}
if ($_FILES['attachment']['type'] == 'image/jpg') {
$_FILES['attachment']['type'] = 'image/jpeg';
}
// If there's an attachment, check it and upload it
if ($_FILES['attachment']['size'] > 0 && $forumpermissions['canpostattachments'] != 0 && ($mybb->settings['maxattachments'] == 0 || $attachcount < $mybb->settings['maxattachments'])) {
require_once MYBB_ROOT . "inc/functions_upload.php";
$attachedfile = upload_attachment($_FILES['attachment'], false);
}
if (empty($attachedfile)) {
return xmlrespfalse("No file uploaded");
}
//return xmlrespfalse(print_r($attachedfile, true));
if ($attachedfile['error']) {
return xmlrespfalse(implode(" :: ", $attachedfile['error']));
}
$result = new xmlrpcval(array('attachment_id' => new xmlrpcval($attachedfile['aid'], 'string'), 'group_id' => new xmlrpcval($posthash, 'string'), 'result' => new xmlrpcval(true, 'boolean'), 'result_text' => new xmlrpcval('', 'base64'), 'file_size' => new xmlrpcval($attachedfile['filesize'], 'int')), 'struct');
return new xmlrpcresp($result);
}
示例2: create_checked
function create_checked($file, $forum_id, $mimetype = 'application/octetstream')
{
global $user;
if (!file_exists($file)) {
trigger_error('FILE_NOT_FOUND', E_USER_ERROR);
}
$filedata = array('realname' => basename($file), 'size' => filesize($file), 'type' => $mimetype);
$filedata = upload_attachment(false, $forum_id, true, $file, false, $filedata);
if ($filedata['post_attach'] && !sizeof($filedata['error'])) {
$attachment = new attachment();
$attachment->poster_id = $user->data['user_id'];
$attachment->physical_filename = $filedata['physical_filename'];
$attachment->real_filename = $filedata['real_filename'];
$attachment->extension = $filedata['extension'];
$attachment->mimetype = $filedata['mimetype'];
$attachment->filesize = $filedata['filesize'];
$attachment->filetime = $filedata['filetime'];
$attachment->thumbnail = $filedata['thumbnail'];
$attachment->submit();
return $attachment;
} else {
trigger_error(implode('<br/>', $filedata['error']), E_USER_ERROR);
}
}
示例3: parse_attachments
/**
* Parse Attachments
*/
function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
{
global $config, $auth, $user, $phpbb_root_path, $phpEx, $db;
$error = array();
$num_attachments = sizeof($this->attachment_data);
$this->filename_data['filecomment'] = utf8_normalize_nfc(request_var('filecomment', '', true));
$upload_file = isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name']) ? true : false;
$add_file = isset($_POST['add_file']) ? true : false;
$delete_file = isset($_POST['delete_file']) ? true : false;
// First of all adjust comments if changed
$actual_comment_list = utf8_normalize_nfc(request_var('comment_list', array(''), true));
foreach ($actual_comment_list as $comment_key => $comment) {
if (!isset($this->attachment_data[$comment_key])) {
continue;
}
if ($this->attachment_data[$comment_key]['attach_comment'] != $actual_comment_list[$comment_key]) {
$this->attachment_data[$comment_key]['attach_comment'] = $actual_comment_list[$comment_key];
}
}
$cfg = array();
$cfg['max_attachments'] = $is_message ? $config['max_attachments_pm'] : $config['max_attachments'];
$forum_id = $is_message ? 0 : $forum_id;
if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file) {
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id)) {
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
$error = $filedata['error'];
if ($filedata['post_attach'] && !sizeof($error)) {
$sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
$db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$new_entry = array('attach_id' => $db->sql_nextid(), 'is_orphan' => 1, 'real_filename' => $filedata['real_filename'], 'attach_comment' => $this->filename_data['filecomment']);
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
$this->filename_data['filecomment'] = '';
// This Variable is set to false here, because Attachments are entered into the
// Database in two modes, one if the id_list is 0 and the second one if post_attach is true
// Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
// but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
//
// This is very relevant, because it could happen that the post got not submitted, but we do not
// know this circumstance here. We could be at the posting page or we could be redirected to the entered
// post. :)
$filedata['post_attach'] = false;
}
} else {
$error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
}
}
if ($preview || $refresh || sizeof($error)) {
// Perform actions on temporary attachments
if ($delete_file) {
include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
$index = array_keys(request_var('delete_file', array(0 => 0)));
$index = !empty($index) ? $index[0] : false;
if ($index !== false && !empty($this->attachment_data[$index])) {
// delete selected attachment
if ($this->attachment_data[$index]['is_orphan']) {
$sql = 'SELECT attach_id, physical_filename, thumbnail
FROM ' . ATTACHMENTS_TABLE . '
WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id'] . '
AND is_orphan = 1
AND poster_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
phpbb_unlink($row['physical_filename'], 'file');
if ($row['thumbnail']) {
phpbb_unlink($row['physical_filename'], 'thumbnail');
}
$db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id']);
}
} else {
delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
}
unset($this->attachment_data[$index]);
$this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "(\\1 == \$index) ? '' : ((\\1 > \$index) ? '[attachment=' . (\\1 - 1) . ']\\2[/attachment]' : '\\0')", $this->message);
// Reindex Array
$this->attachment_data = array_values($this->attachment_data);
}
} else {
if (($add_file || $preview) && $upload_file) {
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id)) {
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
$error = array_merge($error, $filedata['error']);
if (!sizeof($error)) {
$sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
$db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$new_entry = array('attach_id' => $db->sql_nextid(), 'is_orphan' => 1, 'real_filename' => $filedata['real_filename'], 'attach_comment' => $this->filename_data['filecomment']);
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
$this->filename_data['filecomment'] = '';
}
} else {
$error[] = sprintf($user->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
}
}
}
//.........这里部分代码省略.........
示例4: upload_attachment
} else {
$attachwhere = "posthash='" . $db->escape_string($mybb->get_input('posthash')) . "'";
}
// If there's an attachment, check it and upload it
if ($forumpermissions['canpostattachments'] != 0) {
// If attachment exists..
if (!empty($_FILES['attachment']['name']) && !empty($_FILES['attachment']['type'])) {
if ($_FILES['attachment']['size'] > 0) {
$query = $db->simple_select("attachments", "aid", "filename='" . $db->escape_string($_FILES['attachment']['name']) . "' AND {$attachwhere}");
$updateattach = $db->fetch_field($query, "aid");
require_once MYBB_ROOT . "inc/functions_upload.php";
$update_attachment = false;
if ($updateattach > 0 && $mybb->get_input('updateattachment')) {
$update_attachment = true;
}
$attachedfile = upload_attachment($_FILES['attachment'], $update_attachment);
} else {
$errors[] = $lang->error_uploadempty;
$mybb->input['action'] = "newreply";
}
}
}
if (!empty($attachedfile['error'])) {
$errors[] = $attachedfile['error'];
$mybb->input['action'] = "newreply";
}
if (!$mybb->get_input('submit')) {
$editdraftpid = "<input type=\"hidden\" name=\"pid\" value=\"{$pid}\" />";
$mybb->input['action'] = "newreply";
}
}
示例5: parse_attachments
/**
* Parse Attachments
*/
function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
{
global $config, $auth, $user, $phpbb_root_path, $phpEx, $db, $request;
$error = array();
$num_attachments = sizeof($this->attachment_data);
$this->filename_data['filecomment'] = $request->variable('filecomment', '', true);
$upload = $request->file($form_name);
$upload_file = !empty($upload) && $upload['name'] !== 'none' && trim($upload['name']);
$add_file = isset($_POST['add_file']) ? true : false;
$delete_file = isset($_POST['delete_file']) ? true : false;
// First of all adjust comments if changed
$actual_comment_list = $request->variable('comment_list', array(''), true);
foreach ($actual_comment_list as $comment_key => $comment) {
if (!isset($this->attachment_data[$comment_key])) {
continue;
}
if ($this->attachment_data[$comment_key]['attach_comment'] != $actual_comment_list[$comment_key]) {
$this->attachment_data[$comment_key]['attach_comment'] = $actual_comment_list[$comment_key];
}
}
$cfg = array();
$cfg['max_attachments'] = $is_message ? $config['max_attachments_pm'] : $config['max_attachments'];
$forum_id = $is_message ? 0 : $forum_id;
if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file) {
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id)) {
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
$error = $filedata['error'];
if ($filedata['post_attach'] && !sizeof($error)) {
$sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
$db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$new_entry = array('attach_id' => $db->sql_nextid(), 'is_orphan' => 1, 'real_filename' => $filedata['real_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'filesize' => $filedata['filesize']);
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->message = preg_replace_callback('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#', function ($match) {
return '[attachment=' . ($match[1] + 1) . ']' . $match[2] . '[/attachment]';
}, $this->message);
$this->filename_data['filecomment'] = '';
// This Variable is set to false here, because Attachments are entered into the
// Database in two modes, one if the id_list is 0 and the second one if post_attach is true
// Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
// but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
//
// This is very relevant, because it could happen that the post got not submitted, but we do not
// know this circumstance here. We could be at the posting page or we could be redirected to the entered
// post. :)
$filedata['post_attach'] = false;
}
} else {
$error[] = $user->lang('TOO_MANY_ATTACHMENTS', (int) $cfg['max_attachments']);
}
}
if ($preview || $refresh || sizeof($error)) {
if (isset($this->plupload) && $this->plupload->is_active()) {
$json_response = new \phpbb\json_response();
}
// Perform actions on temporary attachments
if ($delete_file) {
include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
$index = array_keys($request->variable('delete_file', array(0 => 0)));
$index = !empty($index) ? $index[0] : false;
if ($index !== false && !empty($this->attachment_data[$index])) {
// delete selected attachment
if ($this->attachment_data[$index]['is_orphan']) {
$sql = 'SELECT attach_id, physical_filename, thumbnail
FROM ' . ATTACHMENTS_TABLE . '
WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id'] . '
AND is_orphan = 1
AND poster_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
phpbb_unlink($row['physical_filename'], 'file');
if ($row['thumbnail']) {
phpbb_unlink($row['physical_filename'], 'thumbnail');
}
$db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id = ' . (int) $this->attachment_data[$index]['attach_id']);
}
} else {
delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
}
unset($this->attachment_data[$index]);
$this->message = preg_replace_callback('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#', function ($match) use($index) {
return $match[1] == $index ? '' : ($match[1] > $index ? '[attachment=' . ($match[1] - 1) . ']' . $match[2] . '[/attachment]' : $match[0]);
}, $this->message);
// Reindex Array
$this->attachment_data = array_values($this->attachment_data);
if (isset($this->plupload) && $this->plupload->is_active()) {
$json_response->send($this->attachment_data);
}
}
} else {
if (($add_file || $preview) && $upload_file) {
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id)) {
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message, false, $this->mimetype_guesser, $this->plupload);
$error = array_merge($error, $filedata['error']);
if (!sizeof($error)) {
$sql_ary = array('physical_filename' => $filedata['physical_filename'], 'attach_comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail'], 'is_orphan' => 1, 'in_message' => $is_message ? 1 : 0, 'poster_id' => $user->data['user_id']);
//.........这里部分代码省略.........
示例6: error
}
if (empty($_POST) && empty($_FILES) && $mybb->input['processed'] == '1') {
error($lang->error_cannot_upload_php_post);
}
if (!$mybb->input['attachmentaid'] && ($mybb->input['newattachment'] || $mybb->input['action'] == "do_newreply" && $mybb->input['submit'] && $_FILES['attachment'])) {
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", "COUNT(aid) as numattachs", $attachwhere);
$attachcount = $db->fetch_field($query, "numattachs");
// If there's an attachment, check it and upload it
if ($_FILES['attachment']['size'] > 0 && $forumpermissions['canpostattachments'] != 0 && ($mybb->settings['maxattachments'] == 0 || $attachcount < $mybb->settings['maxattachments'])) {
require_once MYBB_ROOT . "inc/functions_upload.php";
$attachedfile = upload_attachment($_FILES['attachment']);
}
if ($attachedfile['error']) {
eval("\$attacherror = \"" . $templates->get("error_attacherror") . "\";");
$mybb->input['action'] = "newreply";
}
if (!$mybb->input['submit']) {
$mybb->input['action'] = "newreply";
$editdraftpid = "<input type=\"hidden\" name=\"pid\" value=\"{$pid}\" />";
}
}
// Remove an attachment.
if ($mybb->input['attachmentaid'] && $mybb->input['posthash']) {
require_once MYBB_ROOT . "inc/functions_upload.php";
remove_attachment(0, $mybb->input['posthash'], $mybb->input['attachmentaid']);
if (!$mybb->input['submit']) {
示例7: upload_file
/**
* Upload already uploaded file... huh? are you kidding?
*/
function upload_file($post_id, $topic_id, $forum_id, $upload_dir, $filename)
{
global $message_parser, $db, $user, $phpbb_root_path;
$message_parser->attachment_data = array();
$message_parser->filename_data['filecomment'] = '';
$message_parser->filename_data['filename'] = $phpbb_root_path . $upload_dir . '/' . basename($filename);
$filedata = upload_attachment('local', $forum_id, true, $phpbb_root_path . $upload_dir . '/' . basename($filename));
if ($filedata['post_attach'] && !sizeof($filedata['error'])) {
$message_parser->attachment_data = array('post_msg_id' => $post_id, 'poster_id' => $user->data['user_id'], 'topic_id' => $topic_id, 'in_message' => 0, 'physical_filename' => $filedata['physical_filename'], 'real_filename' => $filedata['real_filename'], 'comment' => $message_parser->filename_data['filecomment'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'thumbnail' => $filedata['thumbnail']);
$message_parser->filename_data['filecomment'] = '';
$filedata['post_attach'] = false;
// Submit Attachment
$attach_sql = $message_parser->attachment_data;
$db->sql_transaction('begin');
$sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $attach_sql);
$db->sql_query($sql);
$sql = 'UPDATE ' . POSTS_TABLE . "\n\t\t\t\tSET post_attachment = 1\n\t\t\t\tWHERE post_id = {$post_id}";
$db->sql_query($sql);
$sql = 'UPDATE ' . TOPICS_TABLE . "\n\t\t\t\tSET topic_attachment = 1\n\t\t\t\tWHERE topic_id = {$topic_id}";
$db->sql_query($sql);
$db->sql_transaction('commit');
add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_id, $filename);
return true;
} else {
if (sizeof($filedata['error'])) {
return sprintf($user->lang['ADMIN_UPLOAD_ERROR'], implode('<br />', $filedata['error']));
}
}
}
示例8: main
//.........这里部分代码省略.........
$template->assign_block_vars('postrow.custom_fields', $field_data);
}
}
}
break;
case 'rating':
case 'recent':
$sql = "SELECT a.*, u.username, u.user_colour, u.user_id
FROM " . GALLERY_PHOTOS_TABLE . ' a
LEFT JOIN ' . USERS_TABLE . " u ON (u.user_id = a.poster_id)
WHERE a.gallery_id <> 0 AND a.extension IN ($extensions)
ORDER BY a.filetime DESC";
$result = $db->sql_query_limit($sql, $config['images_per_page'], $start);
while ($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('imagerow', array(
'PHOTO_COMMENT' => ((mb_strlen($row['photo_comment']) > 20) ? mb_substr($row['photo_comment'], 0, 20) . '...' : $row['photo_comment']),
'PHOTO_MOUSEOVER' => (mb_strlen($row['photo_comment']) > 20) ? $row['photo_comment'] : '',
'PHOTO_NAME' => $row['photo_name'],
'COMMENT_FULL' => $row['photo_comment'],
'IMAGE_TIME' => $user->format_date($row['filetime']),
'IMAGE_VIEWS' => $row['download_count'],
'IMAGE_ID' => $row['photo_id'],
'TOPIC_ID' => ($row['thumbnail']) ? 1 : false,
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $user->lang['GUEST']),
'U_IMAGE_DOWNLOAD' => $this->u_action . "&mode=photo&p={$row['photo_id']}",
'U_IMAGE_THUMBNAIL' => append_sid("{$phpbb_root_path}photo.$phpEx", "id={$row['photo_id']}" . (($row['thumbnail']) ? '&t=1' : '')),
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'MAX_WIDTH' => $config['img_max_thumb_width'],
'MAX_HEIGHT' => $config['img_link_height'],
));
break;
case 'upload':
if (!$user->data['is_registered'])
{
// Can this user view profiles/memberlist?
login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
}
if ($submit)
{
include($phpbb_root_path . 'includes/functions_gallery.' . $phpEx);
$filedata = upload_attachment();
if (!sizeof($filedata['error']))
{
redirect(append_sid("./$filename", "i=$id&mode=$mode&p={$filedata['photo_id']}"));
}
$error_message = '';
foreach ($filedata['error'] as $error)
{
$error_message .= $error . '<br />';
}
trigger_error($error);
}
$template->assign_vars(array(
'I_IMAGE_THUMBNAIL' => ($photo_id) ? append_sid("{$phpbb_root_path}photo.$phpEx", "id=$photo_id&t=1") : '',
'U_ACTION' => $this->u_action . "&mode=$mode",
));
break;
case 'views':
$sql = "SELECT a.*, u.username, u.user_colour, u.user_id
FROM " . GALLERY_PHOTOS_TABLE . ' a
LEFT JOIN ' . USERS_TABLE . " u ON (u.user_id = a.poster_id)
WHERE a.gallery_id <> 0 AND a.extension IN ($extensions)
ORDER BY a.download_count DESC";
$result = $db->sql_query_limit($sql, $config['images_per_page'], $start);
while ($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('imagerow', array(
'PHOTO_COMMENT' => ((mb_strlen($row['photo_comment']) > 20) ? mb_substr($row['photo_comment'], 0, 20) . '...' : $row['photo_comment']),
'PHOTO_MOUSEOVER' => (mb_strlen($row['photo_comment']) > 20) ? $row['photo_comment'] : '',
'PHOTO_NAME' => $row['photo_name'],
'COMMENT_FULL' => $row['photo_comment'],
'IMAGE_TIME' => $user->format_date($row['filetime']),
'IMAGE_VIEWS' => $row['download_count'],
'IMAGE_ID' => $row['photo_id'],
'TOPIC_ID' => ($row['thumbnail']) ? 1 : false,
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $user->lang['GUEST']),
'U_IMAGE_DOWNLOAD' => $this->u_action . "&mode=photo&p={$row['photo_id']}",
'U_IMAGE_THUMBNAIL' => append_sid("{$phpbb_root_path}photo.$phpEx", "id={$row['photo_id']}" . (($row['thumbnail']) ? '&t=1' : '')),
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'MAX_WIDTH' => $config['img_max_thumb_width'],
'MAX_HEIGHT' => $config['img_link_height'],
));
break;
}
$template->assign_vars(array(
'S_' . strtoupper($mode) => true,
));
}
示例9: parse_attachments
function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
{
global $config, $_CLASS, $site_file_root, $forum_id;
$error = array();
$num_attachments = sizeof($this->attachment_data);
$this->filename_data['filecomment'] = request_var('filecomment', '', true);
$upload_file = isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name']) ? true : false;
$add_file = isset($_POST['add_file']);
$delete_file = isset($_POST['delete_file']);
$edit_comment = isset($_POST['edit_comment']);
$cfg = array();
$cfg['max_attachments'] = $is_message ? $config['max_attachments_pm'] : $config['max_attachments'];
$forum_id = $is_message ? 0 : $forum_id;
if ($submit && in_array($mode, array('post', 'reply', 'quote', 'edit')) && $upload_file) {
if ($num_attachments < $cfg['max_attachments'] || $_CLASS['auth']->acl_gets('m_', 'a_')) {
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
$error = $filedata['error'];
if ($filedata['post_attach'] && !sizeof($error)) {
$new_entry = array('physical_filename' => $filedata['physical_filename'], 'comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'attach_id' => 0, 'thumbnail' => $filedata['thumbnail']);
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
$this->filename_data['filecomment'] = '';
// This Variable is set to false here, because Attachments are entered into the
// Database in two modes, one if the id_list is 0 and the second one if post_attach is true
// Since post_attach is automatically switched to true if an Attachment got added to the filesystem,
// but we are assigning an id of 0 here, we have to reset the post_attach variable to false.
//
// This is very relevant, because it could happen that the post got not submitted, but we do not
// know this circumstance here. We could be at the posting page or we could be redirected to the entered
// post. :)
$filedata['post_attach'] = false;
}
} else {
$error[] = sprintf($_CLASS['core_user']->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
}
}
if ($preview || $refresh || sizeof($error)) {
// Perform actions on temporary attachments
if ($delete_file) {
$index = (int) key($_POST['delete_file']);
// delete selected attachment
if (!$this->attachment_data[$index]['attach_id']) {
phpbb_unlink($this->attachment_data[$index]['physical_filename'], 'file');
if ($this->attachment_data[$index]['thumbnail']) {
phpbb_unlink($this->attachment_data[$index]['physical_filename'], 'thumbnail');
}
} else {
delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
}
unset($this->attachment_data[$index]);
$this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "(\\1 == \$index) ? '' : ((\\1 > \$index) ? '[attachment=' . (\\1 - 1) . ']\\2[/attachment]' : '\\0')", $this->message);
// Reindex Array
$this->attachment_data = array_values($this->attachment_data);
} else {
if ($edit_comment || $add_file || $preview) {
if ($edit_comment) {
$actual_comment_list = request_var('comment_list', array(''));
foreach ($actual_comment_list as $index => $entry) {
$this->attachment_data[$index]['comment'] = preg_replace('#&(\\#[0-9]+;)#', '&\\1', $entry);
}
}
if (($add_file || $preview) && $upload_file) {
if ($num_attachments < $cfg['max_attachments'] || $_CLASS['auth']->acl_gets('m_', 'a_')) {
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
$error = array_merge($error, $filedata['error']);
if (!sizeof($error)) {
$new_entry = array('physical_filename' => $filedata['physical_filename'], 'comment' => $this->filename_data['filecomment'], 'real_filename' => $filedata['real_filename'], 'extension' => $filedata['extension'], 'mimetype' => $filedata['mimetype'], 'filesize' => $filedata['filesize'], 'filetime' => $filedata['filetime'], 'attach_id' => 0, 'thumbnail' => $filedata['thumbnail']);
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
$this->message = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
$this->filename_data['filecomment'] = '';
}
} else {
$error[] = sprintf($_CLASS['core_user']->lang['TOO_MANY_ATTACHMENTS'], $cfg['max_attachments']);
}
}
}
}
}
foreach ($error as $error_msg) {
$this->warn_msg[] = $error_msg;
}
}
示例10: upload_file
function upload_file($post_id, $topic_id, $forum_id, $upload_dir, $filename)
{
global $message_parser, $_CLASS;
$message_parser->attachment_data = array();
$message_parser->filename_data['filecomment'] = '';
$message_parser->filename_data['filename'] = $upload_dir . '/' . $filename;
$filedata = upload_attachment('local', $forum_id, true, $upload_dir . '/' . basename($filename));
if ($filedata['post_attach'] && !sizeof($filedata['error']))
{
$message_parser->attachment_data = array(
'post_msg_id' => $post_id,
'poster_id' => $_CLASS['core_user']->data['user_id'],
'topic_id' => $topic_id,
'in_message' => 0,
'physical_filename' => $filedata['physical_filename'],
'real_filename' => $filedata['real_filename'],
'comment' => $message_parser->filename_data['filecomment'],
'extension' => $filedata['extension'],
'mimetype' => $filedata['mimetype'],
'filesize' => $filedata['filesize'],
'filetime' => $filedata['filetime'],
'thumbnail' => $filedata['thumbnail']
);
$message_parser->filename_data['filecomment'] = '';
$filedata['post_attach'] = FALSE;
// Submit Attachment
$attach_sql = $message_parser->attachment_data;
$_CLASS['core_db']->sql_transaction();
$sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $attach_sql);
$_CLASS['core_db']->sql_query($sql);
$sql = 'UPDATE ' . POSTS_TABLE . "
SET post_attachment = 1
WHERE post_id = $post_id";
$_CLASS['core_db']->sql_query($sql);
$sql = 'UPDATE ' . TOPICS_TABLE . "
SET topic_attachment = 1
WHERE topic_id = $topic_id";
$_CLASS['core_db']->sql_query($sql);
$_CLASS['core_db']->sql_transaction('commit');
add_log('admin', sprintf($_CLASS['core_user']->lang['LOG_ATTACH_FILEUPLOAD'], $post_id, $filename));
echo '<span style="color:green">' . $_CLASS['core_user']->lang['SUCCESSFULLY_UPLOADED'] . '</span><br /><br />';
}
else if (sizeof($filedata['error']))
{
echo '<span style="color:red">' . sprintf($_CLASS['core_user']->lang['ADMIN_UPLOAD_ERROR'], implode("<br />\t", $filedata['error'])) . '</span><br /><br />';
}
}