• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP getAttachmentFilename函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP getAttachmentUrl函数代码示例发布时间:2022-05-15
下一篇:
PHP getAtName函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap