当前位置: 首页>>代码示例>>PHP>>正文


PHP getAttachmentFilename函数代码示例

本文整理汇总了PHP中getAttachmentFilename函数的典型用法代码示例。如果您正苦于以下问题:PHP getAttachmentFilename函数的具体用法?PHP getAttachmentFilename怎么用?PHP getAttachmentFilename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getAttachmentFilename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: downloadAvatar

/**
 * downloads a file from a url and stores it locally for avatar use by id_member.
 * - supports GIF, JPG, PNG, BMP and WBMP formats.
 * - detects if GD2 is available.
 * - uses resizeImageFile() to resize to max_width by max_height, and saves the result to a file.
 * - updates the database info for the member's avatar.
 * - returns whether the download and resize was successful.
 *
 * @param string $temporary_path, the full path to the temporary file
 * @param int $memID, member ID
 * @param int $max_width
 * @param int $max_height
 * @return bool, whether the download and resize was successful.
 *
 */
function downloadAvatar($url, $memID, $max_width, $max_height)
{
    global $modSettings, $sourcedir, $smcFunc;
    $ext = !empty($modSettings['avatar_download_png']) ? 'png' : 'jpeg';
    $destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
    // Just making sure there is a non-zero member.
    if (empty($memID)) {
        return false;
    }
    require_once $sourcedir . '/ManageAttachments.php';
    removeAttachments(array('id_member' => $memID));
    $id_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['currentAttachmentUploadDir'] : 1;
    $avatar_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, null, true) : '';
    $smcFunc['db_insert']('', '{db_prefix}attachments', array('id_member' => 'int', 'attachment_type' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-255', 'fileext' => 'string-8', 'size' => 'int', 'id_folder' => 'int'), array($memID, empty($modSettings['custom_avatar_enabled']) ? 0 : 1, $destName, $avatar_hash, $ext, 1, $id_folder), array('id_attach'));
    $attachID = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
    // Retain this globally in case the script wants it.
    $modSettings['new_avatar_data'] = array('id' => $attachID, 'filename' => $destName, 'type' => empty($modSettings['custom_avatar_enabled']) ? 0 : 1);
    $destName = (empty($modSettings['custom_avatar_enabled']) ? is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']] : $modSettings['attachmentUploadDir'] : $modSettings['custom_avatar_dir']) . '/' . $destName . '.tmp';
    // Resize it.
    if (!empty($modSettings['avatar_download_png'])) {
        $success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
    } else {
        $success = resizeImageFile($url, $destName, $max_width, $max_height);
    }
    // Remove the .tmp extension.
    $destName = substr($destName, 0, -4);
    if ($success) {
        // Walk the right path.
        if (!empty($modSettings['currentAttachmentUploadDir'])) {
            if (!is_array($modSettings['attachmentUploadDir'])) {
                $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
            }
            $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
        } else {
            $path = $modSettings['attachmentUploadDir'];
        }
        // Remove the .tmp extension from the attachment.
        if (rename($destName . '.tmp', empty($avatar_hash) ? $destName : $path . '/' . $attachID . '_' . $avatar_hash)) {
            $destName = empty($avatar_hash) ? $destName : $path . '/' . $attachID . '_' . $avatar_hash;
            list($width, $height) = getimagesize($destName);
            $mime_type = 'image/' . $ext;
            // Write filesize in the database.
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}attachments
				SET size = {int:filesize}, width = {int:width}, height = {int:height},
					mime_type = {string:mime_type}
				WHERE id_attach = {int:current_attachment}', array('filesize' => filesize($destName), 'width' => (int) $width, 'height' => (int) $height, 'current_attachment' => $attachID, 'mime_type' => $mime_type));
            return true;
        } else {
            return false;
        }
    } else {
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}attachments
			WHERE id_attach = {int:current_attachment}', array('current_attachment' => $attachID));
        @unlink($destName . '.tmp');
        return false;
    }
}
开发者ID:Glyph13,项目名称:SMF2.1,代码行数:74,代码来源:Subs-Graphics.php

示例2: RepairAttachments

function RepairAttachments()
{
    global $db_prefix, $modSettings, $context, $txt;
    $context['page_title'] = $txt['repair_attachments'];
    $context['description'] = $txt['smf202'];
    $context['selected'] = 'maintenance';
    $context['sub_template'] = 'attachment_repair';
    checkSession('get');
    // If we choose cancel, redirect right back.
    if (isset($_POST['cancel'])) {
        redirectexit('action=manageattachments;sa=maintenance');
    }
    // Try give us a while to sort this out...
    @set_time_limit(600);
    $_GET['step'] = empty($_GET['step']) ? 0 : (int) $_GET['step'];
    $_GET['substep'] = empty($_GET['substep']) ? 0 : (int) $_GET['substep'];
    // Don't recall the session just incase.
    if ($_GET['step'] == 0 && $_GET['substep'] == 0) {
        unset($_SESSION['attachments_to_fix']);
        unset($_SESSION['attachments_to_fix2']);
        // If we're actually fixing stuff - work out what.
        if (isset($_GET['fixErrors'])) {
            // Nothing?
            if (empty($_POST['to_fix'])) {
                redirectexit('action=manageattachments;sa=maintenance');
            }
            $_SESSION['attachments_to_fix'] = array();
            //!!! No need to do this I think.
            foreach ($_POST['to_fix'] as $key => $value) {
                $_SESSION['attachments_to_fix'][] = $value;
            }
        }
    }
    $to_fix = !empty($_SESSION['attachments_to_fix']) ? $_SESSION['attachments_to_fix'] : array();
    $context['repair_errors'] = isset($_SESSION['attachments_to_fix2']) ? $_SESSION['attachments_to_fix2'] : array();
    $fix_errors = isset($_GET['fixErrors']) ? true : false;
    // All the valid problems are here:
    $context['repair_errors'] = array('missing_thumbnail_parent' => 0, 'parent_missing_thumbnail' => 0, 'file_missing_on_disk' => 0, 'file_wrong_size' => 0, 'file_size_of_zero' => 0, 'attachment_no_msg' => 0, 'avatar_no_member' => 0);
    // Get stranded thumbnails.
    if ($_GET['step'] <= 0) {
        $result = db_query("\n\t\t\tSELECT MAX(ID_ATTACH)\n\t\t\tFROM {$db_prefix}attachments\n\t\t\tWHERE attachmentType = 3", __FILE__, __LINE__);
        list($thumbnails) = mysql_fetch_row($result);
        mysql_free_result($result);
        for (; $_GET['substep'] < $thumbnails; $_GET['substep'] += 500) {
            $to_remove = array();
            $result = db_query("\n\t\t\t\tSELECT thumb.ID_ATTACH, thumb.filename, thumb.file_hash\n\t\t\t\tFROM {$db_prefix}attachments AS thumb\n\t\t\t\t\tLEFT JOIN {$db_prefix}attachments AS tparent ON (tparent.ID_THUMB = thumb.ID_ATTACH)\n\t\t\t\tWHERE thumb.ID_ATTACH BETWEEN {$_GET['substep']} AND {$_GET['substep']} + 499\n\t\t\t\t\tAND thumb.attachmentType = 3\n\t\t\t\t\tAND tparent.ID_ATTACH IS NULL\n\t\t\t\tGROUP BY thumb.ID_ATTACH", __FILE__, __LINE__);
            while ($row = mysql_fetch_assoc($result)) {
                $to_remove[] = $row['ID_ATTACH'];
                $context['repair_errors']['missing_thumbnail_parent']++;
                // If we are repairing remove the file from disk now.
                if ($fix_errors && in_array('missing_thumbnail_parent', $to_fix)) {
                    $filename = getAttachmentFilename($row['filename'], $row['ID_ATTACH'], false, $row['file_hash']);
                    @unlink($filename);
                }
            }
            if (mysql_num_rows($result) != 0) {
                $to_fix[] = 'missing_thumbnail_parent';
            }
            mysql_free_result($result);
            // Do we need to delete what we have?
            if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) {
                db_query("\n\t\t\t\t\tDELETE FROM {$db_prefix}attachments\n\t\t\t\t\tWHERE ID_ATTACH IN (" . implode(', ', $to_remove) . ")\n\t\t\t\t\t\tAND attachmentType = 3", __FILE__, __LINE__);
            }
            pauseAttachmentMaintenance($to_fix, $thumbnails);
        }
        $_GET['step'] = 1;
        $_GET['substep'] = 0;
        pauseAttachmentMaintenance($to_fix);
    }
    // Find parents which think they have thumbnails, but actually, don't.
    if ($_GET['step'] <= 1) {
        $result = db_query("\n\t\t\tSELECT MAX(ID_ATTACH)\n\t\t\tFROM {$db_prefix}attachments\n\t\t\tWHERE ID_THUMB != 0", __FILE__, __LINE__);
        list($thumbnails) = mysql_fetch_row($result);
        mysql_free_result($result);
        for (; $_GET['substep'] < $thumbnails; $_GET['substep'] += 500) {
            $to_update = array();
            $result = db_query("\n\t\t\t\tSELECT a.ID_ATTACH\n\t\t\t\tFROM {$db_prefix}attachments AS a\n\t\t\t\t\tLEFT JOIN {$db_prefix}attachments AS thumb ON (thumb.ID_ATTACH = a.ID_THUMB)\n\t\t\t\tWHERE a.ID_ATTACH BETWEEN {$_GET['substep']} AND {$_GET['substep']} + 499\n\t\t\t\t\tAND a.ID_THUMB != 0\n\t\t\t\t\tAND thumb.ID_ATTACH IS NULL", __FILE__, __LINE__);
            while ($row = mysql_fetch_assoc($result)) {
                $to_update[] = $row['ID_ATTACH'];
                $context['repair_errors']['parent_missing_thumbnail']++;
            }
            if (mysql_num_rows($result) != 0) {
                $to_fix[] = 'parent_missing_thumbnail';
            }
            mysql_free_result($result);
            // Do we need to delete what we have?
            if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) {
                db_query("\n\t\t\t\t\tUPDATE {$db_prefix}attachments\n\t\t\t\t\tSET ID_THUMB = 0\n\t\t\t\t\tWHERE ID_ATTACH IN (" . implode(', ', $to_update) . ")", __FILE__, __LINE__);
            }
            pauseAttachmentMaintenance($to_fix, $thumbnails);
        }
        $_GET['step'] = 2;
        $_GET['substep'] = 0;
        pauseAttachmentMaintenance($to_fix);
    }
    // This may take forever I'm afraid, but life sucks... recount EVERY attachments!
    if ($_GET['step'] <= 2) {
        $result = db_query("\n\t\t\tSELECT MAX(ID_ATTACH)\n\t\t\tFROM {$db_prefix}attachments", __FILE__, __LINE__);
        list($thumbnails) = mysql_fetch_row($result);
        mysql_free_result($result);
//.........这里部分代码省略.........
开发者ID:alencarmo,项目名称:OCF,代码行数:101,代码来源:ManageAttachments.php

示例3: RepairAttachments

function RepairAttachments()
{
    global $modSettings, $context, $txt, $smcFunc;
    checkSession('get');
    // If we choose cancel, redirect right back.
    if (isset($_POST['cancel'])) {
        redirectexit('action=admin;area=manageattachments;sa=maintenance');
    }
    // Try give us a while to sort this out...
    @set_time_limit(600);
    $_GET['step'] = empty($_GET['step']) ? 0 : (int) $_GET['step'];
    $_GET['substep'] = empty($_GET['substep']) ? 0 : (int) $_GET['substep'];
    // Don't recall the session just in case.
    if ($_GET['step'] == 0 && $_GET['substep'] == 0) {
        unset($_SESSION['attachments_to_fix'], $_SESSION['attachments_to_fix2']);
        // If we're actually fixing stuff - work out what.
        if (isset($_GET['fixErrors'])) {
            // Nothing?
            if (empty($_POST['to_fix'])) {
                redirectexit('action=admin;area=manageattachments;sa=maintenance');
            }
            $_SESSION['attachments_to_fix'] = array();
            //!!! No need to do this I think.
            foreach ($_POST['to_fix'] as $key => $value) {
                $_SESSION['attachments_to_fix'][] = $value;
            }
        }
    }
    // All the valid problems are here:
    $context['repair_errors'] = array('missing_thumbnail_parent' => 0, 'parent_missing_thumbnail' => 0, 'file_missing_on_disk' => 0, 'file_wrong_size' => 0, 'file_size_of_zero' => 0, 'attachment_no_msg' => 0, 'avatar_no_member' => 0, 'wrong_folder' => 0);
    $to_fix = !empty($_SESSION['attachments_to_fix']) ? $_SESSION['attachments_to_fix'] : array();
    $context['repair_errors'] = isset($_SESSION['attachments_to_fix2']) ? $_SESSION['attachments_to_fix2'] : $context['repair_errors'];
    $fix_errors = isset($_GET['fixErrors']) ? true : false;
    // Get stranded thumbnails.
    if ($_GET['step'] <= 0) {
        $result = $smcFunc['db_query']('', '
			SELECT MAX(id_attach)
			FROM {db_prefix}attachments
			WHERE attachment_type = {int:thumbnail}', array('thumbnail' => 3));
        list($thumbnails) = $smcFunc['db_fetch_row']($result);
        $smcFunc['db_free_result']($result);
        for (; $_GET['substep'] < $thumbnails; $_GET['substep'] += 500) {
            $to_remove = array();
            $result = $smcFunc['db_query']('', '
				SELECT thumb.id_attach, thumb.id_folder, thumb.filename, thumb.file_hash
				FROM {db_prefix}attachments AS thumb
					LEFT JOIN {db_prefix}attachments AS tparent ON (tparent.id_thumb = thumb.id_attach)
				WHERE thumb.id_attach BETWEEN {int:substep} AND {int:substep} + 499
					AND thumb.attachment_type = {int:thumbnail}
					AND tparent.id_attach IS NULL', array('thumbnail' => 3, 'substep' => $_GET['substep']));
            while ($row = $smcFunc['db_fetch_assoc']($result)) {
                // Only do anything once... just in case
                if (!isset($to_remove[$row['id_attach']])) {
                    $to_remove[$row['id_attach']] = $row['id_attach'];
                    $context['repair_errors']['missing_thumbnail_parent']++;
                    // If we are repairing remove the file from disk now.
                    if ($fix_errors && in_array('missing_thumbnail_parent', $to_fix)) {
                        $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
                        @unlink($filename);
                    }
                }
            }
            if ($smcFunc['db_num_rows']($result) != 0) {
                $to_fix[] = 'missing_thumbnail_parent';
            }
            $smcFunc['db_free_result']($result);
            // Do we need to delete what we have?
            if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) {
                $smcFunc['db_query']('', '
					DELETE FROM {db_prefix}attachments
					WHERE id_attach IN ({array_int:to_remove})
						AND attachment_type = {int:attachment_type}', array('to_remove' => $to_remove, 'attachment_type' => 3));
            }
            pauseAttachmentMaintenance($to_fix, $thumbnails);
        }
        $_GET['step'] = 1;
        $_GET['substep'] = 0;
        pauseAttachmentMaintenance($to_fix);
    }
    // Find parents which think they have thumbnails, but actually, don't.
    if ($_GET['step'] <= 1) {
        $result = $smcFunc['db_query']('', '
			SELECT MAX(id_attach)
			FROM {db_prefix}attachments
			WHERE id_thumb != {int:no_thumb}', array('no_thumb' => 0));
        list($thumbnails) = $smcFunc['db_fetch_row']($result);
        $smcFunc['db_free_result']($result);
        for (; $_GET['substep'] < $thumbnails; $_GET['substep'] += 500) {
            $to_update = array();
            $result = $smcFunc['db_query']('', '
				SELECT a.id_attach
				FROM {db_prefix}attachments AS a
					LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)
				WHERE a.id_attach BETWEEN {int:substep} AND {int:substep} + 499
					AND a.id_thumb != {int:no_thumb}
					AND thumb.id_attach IS NULL', array('no_thumb' => 0, 'substep' => $_GET['substep']));
            while ($row = $smcFunc['db_fetch_assoc']($result)) {
                $to_update[] = $row['id_attach'];
                $context['repair_errors']['parent_missing_thumbnail']++;
            }
//.........这里部分代码省略.........
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:101,代码来源:ManageAttachments.php

示例4: messagesAttachments

/**
 * Load message image attachments for use in the print page function
 * Returns array of file attachment name along with width/height properties
 * Will only return approved attachments
 *
 * @param int[] $id_messages
 */
function messagesAttachments($id_messages)
{
    global $modSettings;
    $db = database();
    $request = $db->query('', '
		SELECT
			a.id_attach, a.id_msg, a.approved, a.width, a.height, a.file_hash, a.filename, a.id_folder, a.mime_type
		FROM {db_prefix}attachments AS a
		WHERE a.id_msg IN ({array_int:message_list})
			AND a.attachment_type = {int:attachment_type}', array('message_list' => $id_messages, 'attachment_type' => 0, 'is_approved' => 1));
    $temp = array();
    $printattach = array();
    while ($row = $db->fetch_assoc($request)) {
        $temp[$row['id_attach']] = $row;
        if (!isset($printattach[$row['id_msg']])) {
            $printattach[$row['id_msg']] = array();
        }
    }
    $db->free_result($request);
    ksort($temp);
    // Load them into $context so the template can use them
    foreach ($temp as $row) {
        if (!empty($row['width']) && !empty($row['height'])) {
            if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $row['height'] * ($modSettings['max_image_width'] / $row['width']) <= $modSettings['max_image_height'])) {
                if ($row['width'] > $modSettings['max_image_width']) {
                    $row['height'] = floor($row['height'] * ($modSettings['max_image_width'] / $row['width']));
                    $row['width'] = $modSettings['max_image_width'];
                }
            } elseif (!empty($modSettings['max_image_width'])) {
                if ($row['height'] > $modSettings['max_image_height']) {
                    $row['width'] = floor($row['width'] * $modSettings['max_image_height'] / $row['height']);
                    $row['height'] = $modSettings['max_image_height'];
                }
            }
            $row['filename'] = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
            // save for the template
            $printattach[$row['id_msg']][] = $row;
        }
    }
    return $printattach;
}
开发者ID:Ralkage,项目名称:Elkarte,代码行数:48,代码来源:Topic.subs.php

示例5: makeAvatarChanges


//.........这里部分代码省略.........
        $_POST['avatar'] = preg_match('~^([\\w _!@%*=\\-#()\\[\\]&.,]+/)?[\\w _!@%*=\\-#()\\[\\]&.,]+$~', $_POST['avatar']) != 0 && preg_match('/\\.\\./', $_POST['avatar']) == 0 && file_exists($modSettings['avatar_directory'] . '/' . $_POST['avatar']) ? $_POST['avatar'] == 'blank.gif' ? '' : $_POST['avatar'] : '';
        // Get rid of their old avatar. (if uploaded.)
        removeAttachments('a.ID_MEMBER = ' . $memID);
    } elseif ($_POST['avatar_choice'] == 'external' && allowedTo('profile_remote_avatar') && strtolower(substr($_POST['userpicpersonal'], 0, 7)) == 'http://' && empty($modSettings['avatar_download_external'])) {
        // Remove any attached avatar...
        removeAttachments('a.ID_MEMBER = ' . $memID);
        $_POST['avatar'] = preg_replace('~action(=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']);
        if ($_POST['avatar'] == 'http://' || $_POST['avatar'] == 'http:///') {
            $_POST['avatar'] = '';
        } elseif (substr($_POST['avatar'], 0, 7) != 'http://') {
            $post_errors[] = 'bad_avatar';
        } elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) {
            // Now let's validate the avatar.
            $sizes = url_image_size($_POST['avatar']);
            if (is_array($sizes) && ($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external']) || $sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))) {
                // Houston, we have a problem. The avatar is too large!!
                if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
                    $post_errors[] = 'bad_avatar';
                } elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') {
                    require_once $sourcedir . '/Subs-Graphics.php';
                    if (downloadAvatar($_POST['avatar'], $memID, $modSettings['avatar_max_width_external'], $modSettings['avatar_max_height_external'])) {
                        $_POST['avatar'] = '';
                    } else {
                        $post_errors[] = 'bad_avatar';
                    }
                }
            }
        }
    } elseif ($_POST['avatar_choice'] == 'upload' && allowedTo('profile_upload_avatar') || $downloadedExternalAvatar) {
        if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '' || $downloadedExternalAvatar) {
            // Get the dimensions of the image.
            if (!$downloadedExternalAvatar) {
                if (!is_writable($uploadDir)) {
                    fatal_lang_error('attachments_no_write');
                }
                if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $uploadDir . '/avatar_tmp_' . $memID)) {
                    fatal_lang_error('smf124');
                }
                $_FILES['attachment']['tmp_name'] = $uploadDir . '/avatar_tmp_' . $memID;
            }
            $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
            // No size, then it's probably not a valid pic.
            if ($sizes === false) {
                $post_errors[] = 'bad_avatar';
            } elseif (!empty($modSettings['avatar_max_width_upload']) && $sizes[0] > $modSettings['avatar_max_width_upload'] || !empty($modSettings['avatar_max_height_upload']) && $sizes[1] > $modSettings['avatar_max_height_upload']) {
                if (!empty($modSettings['avatar_resize_upload'])) {
                    // Attempt to chmod it.
                    @chmod($uploadDir . '/avatar_tmp_' . $memID, 0644);
                    require_once $sourcedir . '/Subs-Graphics.php';
                    downloadAvatar($uploadDir . '/avatar_tmp_' . $memID, $memID, $modSettings['avatar_max_width_upload'], $modSettings['avatar_max_height_upload']);
                } else {
                    $post_errors[] = 'bad_avatar';
                }
            } elseif (is_array($sizes)) {
                // Though not an exhaustive list, better safe than sorry.
                $fp = fopen($_FILES['attachment']['tmp_name'], 'rb');
                if (!$fp) {
                    fatal_lang_error('smf124');
                }
                // Now try to find an infection.
                while (!feof($fp)) {
                    if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', fgets($fp, 4096)) === 1) {
                        if (file_exists($uploadDir . '/avatar_tmp_' . $memID)) {
                            @unlink($uploadDir . '/avatar_tmp_' . $memID);
                        }
                        fatal_lang_error('smf124');
                    }
                }
                fclose($fp);
                $extensions = array('1' => '.gif', '2' => '.jpg', '3' => '.png', '6' => '.bmp');
                $extension = isset($extensions[$sizes[2]]) ? $extensions[$sizes[2]] : '.bmp';
                $destName = 'avatar_' . $memID . $extension;
                list($width, $height) = getimagesize($_FILES['attachment']['tmp_name']);
                // Remove previous attachments this member might have had.
                removeAttachments('a.ID_MEMBER = ' . $memID);
                $file_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, true) : '';
                db_query("\n\t\t\t\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t\t\t\t(ID_MEMBER, attachmentType, filename, file_hash, size, width, height)\n\t\t\t\t\tVALUES ({$memID}, " . (empty($modSettings['custom_avatar_enabled']) ? '0' : '1') . ", '{$destName}', '" . (empty($file_hash) ? "" : "{$file_hash}") . "', " . filesize($_FILES['attachment']['tmp_name']) . ", " . (int) $width . ", " . (int) $height . ")", __FILE__, __LINE__);
                $attachID = db_insert_id();
                // Try to move this avatar.
                $destinationPath = $uploadDir . '/' . (empty($file_hash) ? $destName : $attachID . '_' . $file_hash);
                if (!rename($_FILES['attachment']['tmp_name'], $destinationPath)) {
                    // The move failed, get rid of it and die.
                    db_query("\n\t\t\t\t\t\tDELETE FROM {$db_prefix}attachments\n\t\t\t\t\t\tWHERE ID_ATTACH = {$attachID}", __FILE__, __LINE__);
                    fatal_lang_error('smf124');
                }
                // Attempt to chmod it.
                @chmod($destinationPath, 0644);
            }
            $_POST['avatar'] = '';
            // Delete any temporary file.
            if (file_exists($uploadDir . '/avatar_tmp_' . $memID)) {
                @unlink($uploadDir . '/avatar_tmp_' . $memID);
            }
        } else {
            $_POST['avatar'] = '';
        }
    } else {
        $_POST['avatar'] = '';
    }
}
开发者ID:alencarmo,项目名称:OCF,代码行数:101,代码来源:Profile.php

示例6: shd_attachment_info

function shd_attachment_info($attach_info)
{
    global $scripturl, $context, $modSettings, $txt, $sourcedir, $smcFunc;
    $filename = preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($attach_info['filename']));
    $deleteable = shd_allowed_to('shd_delete_attachment', $context['ticket']['dept']);
    $attach = array('id' => $attach_info['id_attach'], 'name' => $filename, 'size' => round($attach_info['filesize'] / 1024, 2) . ' ' . $txt['kilobyte'], 'byte_size' => $attach_info['filesize'], 'href' => $scripturl . '?action=dlattach;ticket=' . $context['ticket_id'] . '.0;attach=' . $attach_info['id_attach'], 'link' => shd_attach_icon($filename) . '&nbsp;<a href="' . $scripturl . '?action=dlattach;ticket=' . $context['ticket_id'] . '.0;attach=' . $attach_info['id_attach'] . '">' . htmlspecialchars($attach_info['filename']) . '</a>', 'is_image' => !empty($modSettings['attachmentShowImages']) && !empty($attach_info['width']) && !empty($attach_info['height']), 'can_delete' => $deleteable);
    if ($attach['is_image']) {
        $attach += array('real_width' => $attach_info['width'], 'width' => $attach_info['width'], 'real_height' => $attach_info['height'], 'height' => $attach_info['height']);
        // Let's see, do we want thumbs?
        if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attach_info['width'] > $modSettings['attachmentThumbWidth'] || $attach_info['height'] > $modSettings['attachmentThumbHeight']) && strlen($attach_info['filename']) < 249) {
            // A proper thumb doesn't exist yet? Create one!
            if (empty($attach_info['id_thumb']) || $attach_info['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attach_info['thumb_height'] > $modSettings['attachmentThumbHeight'] || $attach_info['thumb_width'] < $modSettings['attachmentThumbWidth'] && $attach_info['thumb_height'] < $modSettings['attachmentThumbHeight']) {
                $filename = getAttachmentFilename($attach_info['filename'], $attach_info['id_attach'], $attach_info['id_folder']);
                require_once $sourcedir . '/Subs-Graphics.php';
                if (createThumbnail($filename, $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight'])) {
                    // So what folder are we putting this image in?
                    if (!empty($modSettings['currentAttachmentUploadDir'])) {
                        if (!is_array($modSettings['attachmentUploadDir'])) {
                            $modSettings['attachmentUploadDir'] = json_decode($modSettings['attachmentUploadDir'], true);
                        }
                        $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
                        $id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
                    } else {
                        $path = $modSettings['attachmentUploadDir'];
                        $id_folder_thumb = 1;
                    }
                    // Calculate the size of the created thumbnail.
                    $size = @getimagesize($filename . '_thumb');
                    list($attach_info['thumb_width'], $attach_info['thumb_height']) = $size;
                    $thumb_size = filesize($filename . '_thumb');
                    // These are the only valid image types for SMF.
                    $validImageTypes = array(1 => 'gif', 2 => 'jpeg', 3 => 'png', 5 => 'psd', 6 => 'bmp', 7 => 'tiff', 8 => 'tiff', 9 => 'jpeg', 14 => 'iff');
                    // What about the extension?
                    $thumb_ext = isset($validImageTypes[$size[2]]) ? $validImageTypes[$size[2]] : '';
                    // Figure out the mime type.
                    if (!empty($size['mime'])) {
                        $thumb_mime = $size['mime'];
                    } else {
                        $thumb_mime = 'image/' . $thumb_ext;
                    }
                    $thumb_filename = $attach_info['filename'] . '_thumb';
                    $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
                    // Add this beauty to the database.
                    $smcFunc['db_insert']('', '{db_prefix}attachments', array('id_folder' => 'int', 'id_msg' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'size' => 'int', 'width' => 'int', 'height' => 'int', 'fileext' => 'string', 'mime_type' => 'string'), array($id_folder_thumb, 0, 3, $thumb_filename, $thumb_hash, (int) $thumb_size, (int) $attach_info['thumb_width'], (int) $attach_info['thumb_height'], $thumb_ext, $thumb_mime), array('id_attach'));
                    $old_id_thumb = $attach_info['id_thumb'];
                    $attach_info['id_thumb'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
                    if (!empty($attach_info['id_thumb'])) {
                        // Update the tables to notify that we has us a thumbnail
                        $smcFunc['db_query']('', '
							UPDATE {db_prefix}attachments
							SET id_thumb = {int:id_thumb}
							WHERE id_attach = {int:id_attach}', array('id_thumb' => $attach_info['id_thumb'], 'id_attach' => $attach_info['id_attach']));
                        $smcFunc['db_insert']('replace', '{db_prefix}helpdesk_attachments', array('id_attach' => 'int', 'id_ticket' => 'int', 'id_msg' => 'int'), array($attach_info['id_thumb'], $attach_info['id_ticket'], $attach_info['id_msg']), array('id_attach'));
                        $thumb_realname = getAttachmentFilename($thumb_filename, $attach_info['id_thumb'], $id_folder_thumb, false, $thumb_hash);
                        rename($filename . '_thumb', $thumb_realname);
                        // Do we need to remove an old thumbnail?
                        if (!empty($old_id_thumb)) {
                            require_once $sourcedir . '/ManageAttachments.php';
                            removeAttachments(array('id_attach' => $old_id_thumb), '', false, false);
                        }
                    }
                }
            }
            // Only adjust dimensions on successful thumbnail creation.
            if (!empty($attach_info['thumb_width']) && !empty($attach_info['thumb_height'])) {
                $attach['width'] = $attach_info['thumb_width'];
                $attach['height'] = $attach_info['thumb_height'];
            }
        }
        if (!empty($attach_info['id_thumb'])) {
            $attach['thumbnail'] = array('id' => $attach_info['id_thumb'], 'href' => $scripturl . '?action=dlattach;ticket=' . $context['ticket_id'] . '.0;attach=' . $attach_info['id_thumb'] . ';image');
        }
        $attach['thumbnail']['has_thumb'] = !empty($attach_info['id_thumb']);
        // If thumbnails are disabled, check the maximum size of the image.
        if (!$attach['thumbnail']['has_thumb'] && (!empty($modSettings['max_image_width']) && $attach_info['width'] > $modSettings['max_image_width'] || !empty($modSettings['max_image_height']) && $attach_info['height'] > $modSettings['max_image_height'])) {
            if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $attach_info['height'] * $modSettings['max_image_width'] / $attach_info['width'] <= $modSettings['max_image_height'])) {
                $attach['width'] = $modSettings['max_image_width'];
                $attach['height'] = floor($attach_info['height'] * $modSettings['max_image_width'] / $attach_info['width']);
            } elseif (!empty($modSettings['max_image_width'])) {
                $attach['width'] = floor($attach['width'] * $modSettings['max_image_height'] / $attach['height']);
                $attach['height'] = $modSettings['max_image_height'];
            }
        } elseif ($attach['thumbnail']['has_thumb']) {
            // Make it a popup (since invariably it'll break the layout otherwise)
            $attach['thumbnail']['javascript'] = 'return reqWin(\'' . $attach['href'] . ';image\', ' . ($attach_info['width'] + 20) . ', ' . ($attach_info['height'] + 20) . ', true);';
        }
    }
    return $attach;
}
开发者ID:wintstar,项目名称:Testing,代码行数:89,代码来源:SimpleDesk-Display.php

示例7: createAttachment

function createAttachment(&$attachmentOptions)
{
    global $db_prefix, $modSettings, $sourcedir;
    $attachmentOptions['errors'] = array();
    if (!isset($attachmentOptions['post'])) {
        $attachmentOptions['post'] = 0;
    }
    $already_uploaded = preg_match('~^post_tmp_' . $attachmentOptions['poster'] . '_\\d+$~', $attachmentOptions['tmp_name']) != 0;
    $file_restricted = @ini_get('open_basedir') != '' && !$already_uploaded;
    if ($already_uploaded) {
        $attachmentOptions['tmp_name'] = $modSettings['attachmentUploadDir'] . '/' . $attachmentOptions['tmp_name'];
    }
    // Make sure the file actually exists... sometimes it doesn't.
    if (!$file_restricted && !file_exists($attachmentOptions['tmp_name']) || !$already_uploaded && !is_uploaded_file($attachmentOptions['tmp_name'])) {
        $attachmentOptions['errors'] = array('could_not_upload');
        return false;
    }
    if (!$file_restricted || $already_uploaded) {
        list($attachmentOptions['width'], $attachmentOptions['height']) = @getimagesize($attachmentOptions['tmp_name']);
    }
    // Get the hash if no hash has been given yet.
    if (empty($attachmentOptions['file_hash'])) {
        $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, true);
    }
    // Is the file too big?
    if (!empty($modSettings['attachmentSizeLimit']) && $attachmentOptions['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
        $attachmentOptions['errors'][] = 'too_large';
    }
    if (!empty($modSettings['attachmentCheckExtensions'])) {
        $allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
        foreach ($allowed as $k => $dummy) {
            $allowed[$k] = trim($dummy);
        }
        if (!in_array(strtolower(substr(strrchr($attachmentOptions['name'], '.'), 1)), $allowed)) {
            $attachmentOptions['errors'][] = 'bad_extension';
        }
    }
    if (!empty($modSettings['attachmentDirSizeLimit'])) {
        // Make sure the directory isn't full.
        $dirSize = 0;
        $dir = @opendir($modSettings['attachmentUploadDir']) or fatal_lang_error('smf115b');
        while ($file = readdir($dir)) {
            if (substr($file, 0, -1) == '.') {
                continue;
            }
            if (preg_match('~^post_tmp_\\d+_\\d+$~', $file) != 0) {
                // Temp file is more than 5 hours old!
                if (filemtime($modSettings['attachmentUploadDir'] . '/' . $file) < time() - 18000) {
                    @unlink($modSettings['attachmentUploadDir'] . '/' . $file);
                }
                continue;
            }
            $dirSize += filesize($modSettings['attachmentUploadDir'] . '/' . $file);
        }
        closedir($dir);
        // Too big!  Maybe you could zip it or something...
        if ($attachmentOptions['size'] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024) {
            $attachmentOptions['errors'][] = 'directory_full';
        }
    }
    // Check if the file already exists.... (for those who do not encrypt their filenames...)
    if (empty($modSettings['attachmentEncryptFilenames'])) {
        // Make sure they aren't trying to upload a nasty file.
        $disabledFiles = array('con', 'com1', 'com2', 'com3', 'com4', 'prn', 'aux', 'lpt1', '.htaccess', 'index.php');
        if (in_array(strtolower(basename($attachmentOptions['name'])), $disabledFiles)) {
            $attachmentOptions['errors'][] = 'bad_filename';
        }
        // Check if there's another file with that name...
        $request = db_query("\n\t\t\tSELECT ID_ATTACH\n\t\t\tFROM {$db_prefix}attachments\n\t\t\tWHERE filename = '" . strtolower($attachmentOptions['name']) . "'\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        if (mysql_num_rows($request) > 0) {
            $attachmentOptions['errors'][] = 'taken_filename';
        }
        mysql_free_result($request);
    }
    if (!empty($attachmentOptions['errors'])) {
        return false;
    }
    if (!is_writable($modSettings['attachmentUploadDir'])) {
        fatal_lang_error('attachments_no_write');
    }
    db_query("\n\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t(ID_MSG, filename, file_hash, size, width, height)\n\t\tVALUES (" . (int) $attachmentOptions['post'] . ", SUBSTRING('" . $attachmentOptions['name'] . "', 1, 255), '{$attachmentOptions['file_hash']}', " . (int) $attachmentOptions['size'] . ', ' . (empty($attachmentOptions['width']) ? '0' : (int) $attachmentOptions['width']) . ', ' . (empty($attachmentOptions['height']) ? '0' : (int) $attachmentOptions['height']) . ')', __FILE__, __LINE__);
    $attachmentOptions['id'] = db_insert_id();
    if (empty($attachmentOptions['id'])) {
        return false;
    }
    $attachmentOptions['destination'] = getAttachmentFilename(basename($attachmentOptions['name']), $attachmentOptions['id'], false, $attachmentOptions['file_hash']);
    if ($already_uploaded) {
        rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
    } elseif (!move_uploaded_file($attachmentOptions['tmp_name'], $attachmentOptions['destination'])) {
        fatal_lang_error('smf124');
    } elseif ($file_restricted) {
        list($attachmentOptions['width'], $attachmentOptions['height']) = @getimagesize($attachmentOptions['destination']);
        if (!empty($attachmentOptions['width']) && !empty($attachmentOptions['height'])) {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}attachments\n\t\t\t\tSET\n\t\t\t\t\twidth = " . (int) $attachmentOptions['width'] . ",\n\t\t\t\t\theight = " . (int) $attachmentOptions['height'] . "\n\t\t\t\tWHERE ID_ATTACH = {$attachmentOptions['id']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
    }
    // Attempt to chmod it.
    @chmod($attachmentOptions['destination'], 0644);
    if (!empty($attachmentOptions['skip_thumbnail']) || empty($attachmentOptions['width']) && empty($attachmentOptions['height'])) {
        return true;
//.........这里部分代码省略.........
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:101,代码来源:Subs-Post.php

示例8: createAttachment

function createAttachment(&$attachmentOptions)
{
    global $modSettings, $sourcedir, $backend_subdir;
    require_once $sourcedir . '/lib/Subs-Graphics.php';
    // We need to know where this thing is going.
    if (!empty($modSettings['currentAttachmentUploadDir'])) {
        if (!is_array($modSettings['attachmentUploadDir'])) {
            $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
        }
        // Just use the current path for temp files.
        $attach_dir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
        $id_folder = $modSettings['currentAttachmentUploadDir'];
    } else {
        $attach_dir = $modSettings['attachmentUploadDir'];
        $id_folder = 1;
    }
    $attachmentOptions['errors'] = array();
    if (!isset($attachmentOptions['post'])) {
        $attachmentOptions['post'] = 0;
    }
    if (!isset($attachmentOptions['approved'])) {
        $attachmentOptions['approved'] = 1;
    }
    $already_uploaded = preg_match('~^post_tmp_' . $attachmentOptions['poster'] . '_\\d+$~', $attachmentOptions['tmp_name']) != 0;
    $file_restricted = @ini_get('open_basedir') != '' && !$already_uploaded;
    if ($already_uploaded) {
        $attachmentOptions['tmp_name'] = $attach_dir . '/' . $attachmentOptions['tmp_name'];
    }
    // Make sure the file actually exists... sometimes it doesn't.
    if (!$file_restricted && !file_exists($attachmentOptions['tmp_name']) || !$already_uploaded && !is_uploaded_file($attachmentOptions['tmp_name'])) {
        $attachmentOptions['errors'] = array('could_not_upload');
        return false;
    }
    // These are the only valid image types for SMF.
    $validImageTypes = array(1 => 'gif', 2 => 'jpeg', 3 => 'png', 5 => 'psd', 6 => 'bmp', 7 => 'tiff', 8 => 'tiff', 9 => 'jpeg', 14 => 'iff');
    if (!$file_restricted || $already_uploaded) {
        $size = @getimagesize($attachmentOptions['tmp_name']);
        list($attachmentOptions['width'], $attachmentOptions['height']) = $size;
        // If it's an image get the mime type right.
        if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) {
            // Got a proper mime type?
            if (!empty($size['mime'])) {
                $attachmentOptions['mime_type'] = $size['mime'];
            } elseif (isset($validImageTypes[$size[2]])) {
                $attachmentOptions['mime_type'] = 'image/' . $validImageTypes[$size[2]];
            }
        }
    }
    // Get the hash if no hash has been given yet.
    if (empty($attachmentOptions['file_hash'])) {
        $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
    }
    // Is the file too big?
    if (!empty($modSettings['attachmentSizeLimit']) && $attachmentOptions['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
        $attachmentOptions['errors'][] = 'too_large';
    }
    if (!empty($modSettings['attachmentCheckExtensions'])) {
        $allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
        foreach ($allowed as $k => $dummy) {
            $allowed[$k] = trim($dummy);
        }
        if (!in_array(strtolower(substr(strrchr($attachmentOptions['name'], '.'), 1)), $allowed)) {
            $attachmentOptions['errors'][] = 'bad_extension';
        }
    }
    if (!empty($modSettings['attachmentDirSizeLimit'])) {
        // This is a really expensive operation for big numbers of
        // attachments, which is also very easy to cache. Only do it
        // every ten minutes.
        if (empty($modSettings['attachment_dirsize']) || empty($modSettings['attachment_dirsize_time']) || $modSettings['attachment_dirsize_time'] < time() - 600) {
            // It has been cached - just work with this value for now!
            $dirSize = $modSettings['attachment_dirsize'];
        } else {
            // Make sure the directory isn't full.
            $dirSize = 0;
            $dir = @opendir($attach_dir) or fatal_lang_error('cant_access_upload_path', 'critical');
            while ($file = readdir($dir)) {
                if ($file == '.' || $file == '..') {
                    continue;
                }
                if (preg_match('~^post_tmp_\\d+_\\d+$~', $file) != 0) {
                    // Temp file is more than 5 hours old!
                    if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
                        @unlink($attach_dir . '/' . $file);
                    }
                    continue;
                }
                $dirSize += filesize($attach_dir . '/' . $file);
            }
            closedir($dir);
            updateSettings(array('attachment_dirsize' => $dirSize, 'attachment_dirsize_time' => time()));
        }
        // Too big!  Maybe you could zip it or something...
        if ($attachmentOptions['size'] + $dirSize > $modSettings['attachmentDirSizeLimit'] * 1024) {
            $attachmentOptions['errors'][] = 'directory_full';
        } elseif (!isset($modSettings['attachment_full_notified']) && $modSettings['attachmentDirSizeLimit'] > 4000 && $attachmentOptions['size'] + $dirSize > ($modSettings['attachmentDirSizeLimit'] - 2000) * 1024) {
            require_once $sourcedir . '/lib/Subs-Admin.php';
            emailAdmins('admin_attachments_full');
            updateSettings(array('attachment_full_notified' => 1));
        }
//.........这里部分代码省略.........
开发者ID:norv,项目名称:EosAlpha,代码行数:101,代码来源:Subs-Post.php

示例9: removeAllAttachments

function removeAllAttachments()
{
    global $to_prefix, $smcFunc;
    $result = convert_query("\n\t\tSELECT value\n\t\tFROM {$to_prefix}settings\n\t\tWHERE variable = 'attachmentUploadDir'\n\t\tLIMIT 1");
    list($attachmentUploadDir) = $smcFunc['db_fetch_row']($result);
    $smcFunc['db_free_result']($result);
    // !!! This should probably be done in chunks too.
    $result = convert_query("\n\t\tSELECT id_attach, filename\n\t\tFROM {$to_prefix}attachments");
    while ($row = $smcFunc['db_fetch_assoc']($result)) {
        $filename = $row['filename'];
        $id_attach = $row['id_attach'];
        $physical_filename = getAttachmentFilename($filename, $id_attach);
        if (file_exists($physical_filename)) {
            @unlink($physical_filename);
        }
    }
    $smcFunc['db_free_result']($result);
}
开发者ID:Realms-Network,项目名称:Vanilla-2-to-SMF-2,代码行数:18,代码来源:convert.php

示例10: downloadAvatar

function downloadAvatar($url, $memID, $max_width, $max_height)
{
    global $modSettings, $db_prefix, $sourcedir, $gd2;
    $destName = 'avatar_' . $memID . '.' . (!empty($modSettings['avatar_download_png']) ? 'png' : 'jpeg');
    $default_formats = array('1' => 'gif', '2' => 'jpeg', '3' => 'png', '6' => 'bmp', '15' => 'wbmp');
    // Check to see if GD is installed and what version.
    $testGD = get_extension_funcs('gd');
    // If GD is not installed, this function is pointless.
    if (empty($testGD)) {
        return false;
    }
    // Just making sure there is a non-zero member.
    if (empty($memID)) {
        return false;
    }
    // GD 2 maybe?
    $gd2 = in_array('imagecreatetruecolor', $testGD) && function_exists('imagecreatetruecolor');
    unset($testGD);
    require_once $sourcedir . '/ManageAttachments.php';
    removeAttachments('a.ID_MEMBER = ' . $memID);
    $avatar_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, true) : '';
    db_query("\n\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t(ID_MEMBER, attachmentType, filename, file_hash, size)\n\t\tVALUES ({$memID}, " . (empty($modSettings['custom_avatar_enabled']) ? '0' : '1') . ", '{$destName}', '" . (empty($avatar_hash) ? "" : "{$avatar_hash}") . "', 1)", __FILE__, __LINE__);
    $attachID = db_insert_id();
    $destName = (empty($modSettings['custom_avatar_enabled']) ? $modSettings['attachmentUploadDir'] : $modSettings['custom_avatar_dir']) . '/' . $destName . '.tmp';
    $success = false;
    $sizes = url_image_size($url);
    require_once $sourcedir . '/Subs-Package.php';
    $fp = fopen($destName, 'wb');
    if ($fp && substr($url, 0, 7) == 'http://') {
        $fileContents = fetch_web_data($url);
        // Though not an exhaustive list, better safe than sorry.
        if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', $fileContents) === 1) {
            fclose($fp);
            return false;
        }
        fwrite($fp, $fileContents);
        fclose($fp);
    } elseif ($fp) {
        $fp2 = fopen($url, 'rb');
        $prev_chunk = '';
        while (!feof($fp2)) {
            $cur_chunk = fread($fp2, 8192);
            // Make sure nothing odd came through.
            if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', $prev_chunk . $cur_chunk) === 1) {
                fclose($fp2);
                fclose($fp);
                unlink($destName);
                return false;
            }
            fwrite($fp, $cur_chunk);
            $prev_chunk = $cur_chunk;
        }
        fclose($fp2);
        fclose($fp);
    } else {
        $sizes = array(-1, -1, -1);
    }
    // Gif? That might mean trouble if gif support is not available.
    if ($sizes[2] == 1 && !function_exists('imagecreatefromgif') && function_exists('imagecreatefrompng')) {
        // Download it to the temporary file... use the special gif library... and save as png.
        if ($img = @gif_loadFile($destName) && gif_outputAsPng($img, $destName)) {
            $sizes[2] = 3;
        }
    }
    // A known and supported format?
    if (isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) {
        $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
        if ($src_img = @$imagecreatefrom($destName)) {
            resizeImage($src_img, $destName, imagesx($src_img), imagesy($src_img), $max_width, $max_height);
            $success = true;
        }
    }
    // Remove the .tmp extension.
    $destName = substr($destName, 0, -4);
    if ($success) {
        // Remove the .tmp extension from the attachment.
        if (rename($destName . '.tmp', empty($avatar_hash) ? $destName : $modSettings['attachmentUploadDir'] . '/' . $attachID . '_' . $avatar_hash)) {
            $destName = empty($avatar_hash) ? $destName : $modSettings['attachmentUploadDir'] . '/' . $attachID . '_' . $avatar_hash;
            list($width, $height) = getimagesize($destName);
            // Write filesize in the database.
            db_query("\n\t\t\t\tUPDATE {$db_prefix}attachments\n\t\t\t\tSET size = " . filesize($destName) . ", width = " . (int) $width . ", height = " . (int) $height . "\n\t\t\t\tWHERE ID_ATTACH = {$attachID}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            return true;
        } else {
            return false;
        }
    } else {
        db_query("\n\t\t\tDELETE FROM {$db_prefix}attachments\n\t\t\tWHERE ID_ATTACH = {$attachID}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        @unlink($destName . '.tmp');
        return false;
    }
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:91,代码来源:Subs-Graphics.php

示例11: action_transfer

    /**
     * Maintenance function to move attachments from one directory to another
     */
    public function action_transfer()
    {
        global $modSettings, $txt;
        checkSession();
        // We will need the functions from here
        require_once SUBSDIR . '/Attachments.subs.php';
        require_once SUBSDIR . '/ManageAttachments.subs.php';
        // The list(s) of directory's that are available.
        $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
        if (!empty($modSettings['attachment_basedirectories'])) {
            $modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
        } else {
            $modSettings['basedirectory_for_attachments'] = array();
        }
        // Clean the inputs
        $_POST['from'] = (int) $_POST['from'];
        $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0;
        $_POST['to'] = (int) $_POST['to'];
        $start = !empty($_POST['empty_it']) ? 0 : $modSettings['attachmentDirFileLimit'];
        $_SESSION['checked'] = !empty($_POST['empty_it']) ? true : false;
        // Prepare for the moving
        $limit = 501;
        $results = array();
        $dir_files = 0;
        $current_progress = 0;
        $total_moved = 0;
        $total_not_moved = 0;
        // Need to know where we are moving things from
        if (empty($_POST['from']) || empty($_POST['auto']) && empty($_POST['to'])) {
            $results[] = $txt['attachment_transfer_no_dir'];
        }
        // Same location, that's easy
        if ($_POST['from'] == $_POST['to']) {
            $results[] = $txt['attachment_transfer_same_dir'];
        }
        // No errors so determine how many we may have to move
        if (empty($results)) {
            // Get the total file count for the progress bar.
            $total_progress = getFolderAttachmentCount($_POST['from']);
            $total_progress -= $start;
            if ($total_progress < 1) {
                $results[] = $txt['attachment_transfer_no_find'];
            }
        }
        // Nothing to move (no files in source or below the max limit)
        if (empty($results)) {
            // Moving them automaticaly?
            if (!empty($_POST['auto'])) {
                $modSettings['automanage_attachments'] = 1;
                // Create sub directroys off the root or from an attachment directory?
                $modSettings['use_subdirectories_for_attachments'] = $_POST['auto'] == -1 ? 0 : 1;
                $modSettings['basedirectory_for_attachments'] = $_POST['auto'] > 0 ? $modSettings['attachmentUploadDir'][$_POST['auto']] : $modSettings['basedirectory_for_attachments'];
                // Finaly, where do they need to go
                automanage_attachments_check_directory();
                $new_dir = $modSettings['currentAttachmentUploadDir'];
            } else {
                $new_dir = $_POST['to'];
            }
            $modSettings['currentAttachmentUploadDir'] = $new_dir;
            $break = false;
            while ($break === false) {
                @set_time_limit(300);
                if (function_exists('apache_reset_timeout')) {
                    @apache_reset_timeout();
                }
                // If limits are set, get the file count and size for the destination folder
                if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) {
                    $current_dir = attachDirProperties($new_dir);
                    $dir_files = $current_dir['files'];
                    $dir_size = $current_dir['size'];
                }
                // Find some attachments to move
                list($tomove_count, $tomove) = findAttachmentsToMove($_POST['from'], $start, $limit);
                // Nothing found to move
                if ($tomove_count === 0) {
                    if (empty($current_progress)) {
                        $results[] = $txt['attachment_transfer_no_find'];
                    }
                    break;
                }
                // No more to move after this batch then set the finished flag.
                if ($tomove_count < $limit) {
                    $break = true;
                }
                // Move them
                $moved = array();
                foreach ($tomove as $row) {
                    $source = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
                    $dest = $modSettings['attachmentUploadDir'][$new_dir] . '/' . basename($source);
                    // Size and file count check
                    if (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit'])) {
                        $dir_files++;
                        $dir_size += !empty($row['size']) ? $row['size'] : filesize($source);
                        // If we've reached a directory limit. Do something if we are in auto mode, otherwise set an error.
                        if (!empty($modSettings['attachmentDirSizeLimit']) && $dir_size > $modSettings['attachmentDirSizeLimit'] * 1024 || !empty($modSettings['attachmentDirFileLimit']) && $dir_files > $modSettings['attachmentDirFileLimit']) {
                            // Since we're in auto mode. Create a new folder and reset the counters.
                            if (!empty($_POST['auto'])) {
//.........这里部分代码省略.........
开发者ID:scripple,项目名称:Elkarte,代码行数:101,代码来源:ManageAttachments.controller.php

示例12: loadAttachmentContext

/**
 * This loads an attachment's contextual data including, most importantly, its size if it is an image.
 *
 * What it does:
 * - Pre-condition: $attachments array to have been filled with the proper attachment data, as Display() does.
 * - It requires the view_attachments permission to calculate image size.
 * - It attempts to keep the "aspect ratio" of the posted image in line, even if it has to be resized by
 * the max_image_width and max_image_height settings.
 *
 * @todo change this pre-condition, too fragile and error-prone.
 *
 * @package Attachments
 * @param int $id_msg message number to load attachments for
 * @return array of attachments
 */
function loadAttachmentContext($id_msg)
{
    global $attachments, $modSettings, $txt, $scripturl, $topic;
    // Set up the attachment info - based on code by Meriadoc.
    $attachmentData = array();
    $have_unapproved = false;
    if (isset($attachments[$id_msg]) && !empty($modSettings['attachmentEnable'])) {
        foreach ($attachments[$id_msg] as $i => $attachment) {
            $attachmentData[$i] = array('id' => $attachment['id_attach'], 'name' => preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($attachment['filename'], ENT_COMPAT, 'UTF-8')), 'downloads' => $attachment['downloads'], 'size' => $attachment['filesize'] < 1024000 ? round($attachment['filesize'] / 1024, 2) . ' ' . $txt['kilobyte'] : round($attachment['filesize'] / 1024 / 1024, 2) . ' ' . $txt['megabyte'], 'byte_size' => $attachment['filesize'], 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_attach'], 'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_attach'] . '">' . htmlspecialchars($attachment['filename'], ENT_COMPAT, 'UTF-8') . '</a>', 'is_image' => !empty($attachment['width']) && !empty($attachment['height']) && !empty($modSettings['attachmentShowImages']), 'is_approved' => $attachment['approved'], 'file_hash' => $attachment['file_hash']);
            // If something is unapproved we'll note it so we can sort them.
            if (!$attachment['approved']) {
                $have_unapproved = true;
            }
            if (!$attachmentData[$i]['is_image']) {
                continue;
            }
            $attachmentData[$i]['real_width'] = $attachment['width'];
            $attachmentData[$i]['width'] = $attachment['width'];
            $attachmentData[$i]['real_height'] = $attachment['height'];
            $attachmentData[$i]['height'] = $attachment['height'];
            // Let's see, do we want thumbs?
            if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachment['width'] > $modSettings['attachmentThumbWidth'] || $attachment['height'] > $modSettings['attachmentThumbHeight']) && strlen($attachment['filename']) < 249) {
                // A proper thumb doesn't exist yet? Create one! Or, it needs update.
                if (empty($attachment['id_thumb']) || $attachment['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attachment['thumb_height'] > $modSettings['attachmentThumbHeight'] || $attachment['thumb_width'] < $modSettings['attachmentThumbWidth'] && $attachment['thumb_height'] < $modSettings['attachmentThumbHeight']) {
                    $filename = getAttachmentFilename($attachment['filename'], $attachment['id_attach'], $attachment['id_folder'], false, $attachment['file_hash']);
                    $attachment = array_merge($attachment, updateAttachmentThumbnail($filename, $attachment['id_attach'], $id_msg, $attachment['id_thumb']));
                }
                // Only adjust dimensions on successful thumbnail creation.
                if (!empty($attachment['thumb_width']) && !empty($attachment['thumb_height'])) {
                    $attachmentData[$i]['width'] = $attachment['thumb_width'];
                    $attachmentData[$i]['height'] = $attachment['thumb_height'];
                }
            }
            if (!empty($attachment['id_thumb'])) {
                $attachmentData[$i]['thumbnail'] = array('id' => $attachment['id_thumb'], 'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_thumb'] . ';image');
            }
            $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
            // If thumbnails are disabled, check the maximum size of the image.
            if (!$attachmentData[$i]['thumbnail']['has_thumb'] && (!empty($modSettings['max_image_width']) && $attachment['width'] > $modSettings['max_image_width'] || !empty($modSettings['max_image_height']) && $attachment['height'] > $modSettings['max_image_height'])) {
                if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $attachment['height'] * $modSettings['max_image_width'] / $attachment['width'] <= $modSettings['max_image_height'])) {
                    $attachmentData[$i]['width'] = $modSettings['max_image_width'];
                    $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
                } elseif (!empty($modSettings['max_image_width'])) {
                    $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
                    $attachmentData[$i]['height'] = $modSettings['max_image_height'];
                }
            } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) {
                // If the image is too large to show inline, make it a popup.
                if (!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width'] || !empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']) {
                    $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
                } else {
                    $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
                }
            }
            if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
                $attachmentData[$i]['downloads']++;
            }
        }
    }
    // Do we need to instigate a sort?
    if ($have_unapproved) {
        usort($attachmentData, 'approved_attach_sort');
    }
    return $attachmentData;
}
开发者ID:KeiroD,项目名称:Elkarte,代码行数:80,代码来源:Attachments.subs.php

示例13: createAttachment

/**
 * Create an attachment, with the given array of parameters.
 * - Adds any addtional or missing parameters to $attachmentOptions.
 * - Renames the temporary file.
 * - Creates a thumbnail if the file is an image and the option enabled.
 *
 * @param array $attachmentOptions
 */
function createAttachment(&$attachmentOptions)
{
    global $modSettings, $sourcedir, $smcFunc, $context;
    global $txt, $boarddir;
    require_once $sourcedir . '/Subs-Graphics.php';
    // These are the only valid image types for SMF.
    $validImageTypes = array(1 => 'gif', 2 => 'jpeg', 3 => 'png', 5 => 'psd', 6 => 'bmp', 7 => 'tiff', 8 => 'tiff', 9 => 'jpeg', 14 => 'iff');
    // If this is an image we need to set a few additional parameters.
    $size = @getimagesize($attachmentOptions['tmp_name']);
    list($attachmentOptions['width'], $attachmentOptions['height']) = $size;
    // If it's an image get the mime type right.
    if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) {
        // Got a proper mime type?
        if (!empty($size['mime'])) {
            $attachmentOptions['mime_type'] = $size['mime'];
        } elseif (isset($validImageTypes[$size[2]])) {
            $attachmentOptions['mime_type'] = 'image/' . $validImageTypes[$size[2]];
        }
    }
    // Get the hash if no hash has been given yet.
    if (empty($attachmentOptions['file_hash'])) {
        $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
    }
    // Assuming no-one set the extension let's take a look at it.
    if (empty($attachmentOptions['fileext'])) {
        $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
        if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
            $attachmentOptions['fileext'] = '';
        }
    }
    $smcFunc['db_insert']('', '{db_prefix}attachments', array('id_folder' => 'int', 'id_msg' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-40', 'fileext' => 'string-8', 'size' => 'int', 'width' => 'int', 'height' => 'int', 'mime_type' => 'string-20', 'approved' => 'int'), array((int) $attachmentOptions['id_folder'], (int) $attachmentOptions['post'], $attachmentOptions['name'], $attachmentOptions['file_hash'], $attachmentOptions['fileext'], (int) $attachmentOptions['size'], empty($attachmentOptions['width']) ? 0 : (int) $attachmentOptions['width'], empty($attachmentOptions['height']) ? '0' : (int) $attachmentOptions['height'], !empty($attachmentOptions['mime_type']) ? $attachmentOptions['mime_type'] : '', (int) $attachmentOptions['approved']), array('id_attach'));
    $attachmentOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
    // @todo Add an error here maybe?
    if (empty($attachmentOptions['id'])) {
        return false;
    }
    // Now that we have the attach id, let's rename this sucker and finish up.
    $attachmentOptions['destination'] = getAttachmentFilename(basename($attachmentOptions['name']), $attachmentOptions['id'], $attachmentOptions['id_folder'], false, $attachmentOptions['file_hash']);
    rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
    // If it's not approved then add to the approval queue.
    if (!$attachmentOptions['approved']) {
        $smcFunc['db_insert']('', '{db_prefix}approval_queue', array('id_attach' => 'int', 'id_msg' => 'int'), array($attachmentOptions['id'], (int) $attachmentOptions['post']), array());
    }
    if (empty($modSettings['attachmentThumbnails']) || empty($attachmentOptions['width']) && empty($attachmentOptions['height'])) {
        return true;
    }
    // Like thumbnails, do we?
    if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) {
        if (createThumbnail($attachmentOptions['destination'], $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight'])) {
            // Figure out how big we actually made it.
            $size = @getimagesize($attachmentOptions['destination'] . '_thumb');
            list($thumb_width, $thumb_height) = $size;
            if (!empty($size['mime'])) {
                $thumb_mime = $size['mime'];
            } elseif (isset($validImageTypes[$size[2]])) {
                $thumb_mime = 'image/' . $validImageTypes[$size[2]];
            } else {
                $thumb_mime = '';
            }
            $thumb_filename = $attachmentOptions['name'] . '_thumb';
            $thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
            $thumb_file_hash = getAttachmentFilename($thumb_filename, false, null, true);
            $thumb_path = $attachmentOptions['destination'] . '_thumb';
            // We should check the file size and count here since thumbs are added to the existing totals.
            if (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] == 1 && !empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit'])) {
                $context['dir_size'] = isset($context['dir_size']) ? $context['dir_size'] += $thumb_size : ($context['dir_size'] = 0);
                $context['dir_files'] = isset($context['dir_files']) ? $context['dir_files']++ : ($context['dir_files'] = 0);
                // If the folder is full, try to create a new one and move the thumb to it.
                if ($context['dir_size'] > $modSettings['attachmentDirSizeLimit'] * 1024 || $context['dir_files'] + 2 > $modSettings['attachmentDirFileLimit']) {
                    if (automanage_attachments_by_space()) {
                        rename($thumb_path, $context['attach_dir'] . '/' . $thumb_filename);
                        $thumb_path = $context['attach_dir'] . '/' . $thumb_filename;
                        $context['dir_size'] = $thumb_size;
                        $context['dir_files'] = 1;
                    }
                }
            }
            // If a new folder has been already created. Gotta move this thumb there then.
            if ($modSettings['currentAttachmentUploadDir'] != $attachmentOptions['id_folder']) {
                rename($thumb_path, $context['attach_dir'] . '/' . $thumb_filename);
                $thumb_path = $context['attach_dir'] . '/' . $thumb_filename;
            }
            // To the database we go!
            $smcFunc['db_insert']('', '{db_prefix}attachments', array('id_folder' => 'int', 'id_msg' => 'int', 'attachment_type' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-40', 'fileext' => 'string-8', 'size' => 'int', 'width' => 'int', 'height' => 'int', 'mime_type' => 'string-20', 'approved' => 'int'), array($modSettings['currentAttachmentUploadDir'], (int) $attachmentOptions['post'], 3, $thumb_filename, $thumb_file_hash, $attachmentOptions['fileext'], $thumb_size, $thumb_width, $thumb_height, $thumb_mime, (int) $attachmentOptions['approved']), array('id_attach'));
            $attachmentOptions['thumb'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
            if (!empty($attachmentOptions['thumb'])) {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}attachments
					SET id_thumb = {int:id_thumb}
					WHERE id_attach = {int:id_attach}', array('id_thumb' => $attachmentOptions['thumb'], 'id_attach' => $attachmentOptions['id']));
                rename($thumb_path, getAttachmentFilename($thumb_filename, $attachmentOptions['thumb'], $modSettings['currentAttachmentUploadDir'], false, $thumb_file_hash));
            }
//.........这里部分代码省略.........
开发者ID:Glyph13,项目名称:SMF2.1,代码行数:101,代码来源:Attachments.php

示例14: moveAvatars

/**
 * Move avatars to their new directory.
 *
 * @package Attachments
 */
function moveAvatars()
{
    global $modSettings;
    $db = database();
    $request = $db->query('', '
		SELECT id_attach, id_folder, id_member, filename, file_hash
		FROM {db_prefix}attachments
		WHERE attachment_type = {int:attachment_type}
			AND id_member > {int:guest_id_member}', array('attachment_type' => 0, 'guest_id_member' => 0));
    $updatedAvatars = array();
    while ($row = $db->fetch_assoc($request)) {
        $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
        if (rename($filename, $modSettings['custom_avatar_dir'] . '/' . $row['filename'])) {
            $updatedAvatars[] = $row['id_attach'];
        }
    }
    $db->free_result($request);
    if (!empty($updatedAvatars)) {
        $db->query('', '
			UPDATE {db_prefix}attachments
			SET attachment_type = {int:attachment_type}
			WHERE id_attach IN ({array_int:updated_avatars})', array('updated_avatars' => $updatedAvatars, 'attachment_type' => 1));
    }
}
开发者ID:KeiroD,项目名称:Elkarte,代码行数:29,代码来源:ManageAttachments.subs.php

示例15: Post


//.........这里部分代码省略.........
            $form_message = '';
        }
    }
    // !!! This won't work if you're posting an event.
    if (allowedTo('post_attachment')) {
        if (empty($_SESSION['temp_attachments'])) {
            $_SESSION['temp_attachments'] = array();
        }
        // If this isn't a new post, check the current attachments.
        if (isset($_REQUEST['msg'])) {
            $request = db_query("\n\t\t\t\tSELECT COUNT(*), SUM(size)\n\t\t\t\tFROM {$db_prefix}attachments\n\t\t\t\tWHERE ID_MSG = " . (int) $_REQUEST['msg'] . "\n\t\t\t\t\tAND attachmentType = 0", __FILE__, __LINE__);
            list($quantity, $total_size) = mysql_fetch_row($request);
            mysql_free_result($request);
        } else {
            $quantity = 0;
            $total_size = 0;
        }
        $temp_start = 0;
        if (!empty($_SESSION['temp_attachments'])) {
            foreach ($_SESSION['temp_attachments'] as $attachID => $name) {
                $temp_start++;
                if (preg_match('~^post_tmp_' . $ID_MEMBER . '_\\d+$~', $attachID) == 0) {
                    unset($_SESSION['temp_attachments'][$attachID]);
                    continue;
                }
                if (!empty($_POST['attach_del']) && !in_array($attachID, $_POST['attach_del'])) {
                    $deleted_attachments = true;
                    unset($_SESSION['temp_attachments'][$attachID]);
                    @unlink($modSettings['attachmentUploadDir'] . '/' . $attachID);
                    continue;
                }
                $quantity++;
                $total_size += filesize($modSettings['attachmentUploadDir'] . '/' . $attachID);
                $context['current_attachments'][] = array('name' => getAttachmentFilename($name, false, true), 'id' => $attachID);
            }
        }
        if (!empty($_POST['attach_del'])) {
            $del_temp = array();
            foreach ($_POST['attach_del'] as $i => $dummy) {
                $del_temp[$i] = (int) $dummy;
            }
            foreach ($context['current_attachments'] as $k => $dummy) {
                if (!in_array($dummy['id'], $del_temp)) {
                    $context['current_attachments'][$k]['unchecked'] = true;
                    $deleted_attachments = !isset($deleted_attachments) || is_bool($deleted_attachments) ? 1 : $deleted_attachments + 1;
                    $quantity--;
                }
            }
        }
        if (!empty($_FILES['attachment'])) {
            foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
                if ($_FILES['attachment']['name'][$n] == '') {
                    continue;
                }
                if (!is_uploaded_file($_FILES['attachment']['tmp_name'][$n]) || @ini_get('open_basedir') == '' && !file_exists($_FILES['attachment']['tmp_name'][$n])) {
                    fatal_lang_error('smf124');
                }
                if (!empty($modSettings['attachmentSizeLimit']) && $_FILES['attachment']['size'][$n] > $modSettings['attachmentSizeLimit'] * 1024) {
                    fatal_lang_error('smf122', false, array($modSettings['attachmentSizeLimit']));
                }
                $quantity++;
                if (!empty($modSettings['attachmentNumPerPostLimit']) && $quantity > $modSettings['attachmentNumPerPostLimit']) {
                    fatal_lang_error('attachments_limit_per_post', false, array($modSettings['attachmentNumPerPostLimit']));
                }
                $total_size += $_FILES['attachment']['size'][$n];
                if (!empty($modSettings['attachmentPostLimit']) && $total_size > $modSettings['attachmentPostLimit'] * 1024) {
开发者ID:alencarmo,项目名称:OCF,代码行数:67,代码来源:Post.php


注:本文中的getAttachmentFilename函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。