Файл: user/mail/inc/photo.act.php
Строк: 42
<?php
/* DCMS Special
 * Дата последнего редактирования 03.01.2016
 * Модифицировал densnet
 */
function resizePhoto($attach_id, $size = 640) {
    global $img_x, $img_y, $imgc;
    if ($img_x == $img_y) {
        $dstW = $size;
        $dstH = $size;
    } elseif ($img_x > $img_y) {
        $prop = $img_x / $img_y;
        $dstW = $size;
        $dstH = ceil($dstW / $prop);
    } else {
        $prop = $img_y / $img_x;
        $dstH = $size;
        $dstW = ceil($dstH / $prop);
    }
    $screen = imagecreatetruecolor($dstW, $dstH);
    imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
    imagejpeg($screen, H . 'sys/gallery/' . $size . '/' . $attach_id . '.jpg', 90);
    @chmod(H . 'sys/gallery/' . $size . '/' . $attach_id . '.jpg', 0777);
    imagedestroy($screen);
}
if ($imgc = @imagecreatefromstring(file_get_contents($_FILES['file']['tmp_name']))) {
    $access = 'only_me';
    if (mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `name` = 'Вложения' AND `id_user` = '$user[id]' LIMIT 1"), 0) == 0) {
        mysql_query("INSERT INTO `gallery` (`time_create`, `id_user`, `name`, `time`, `pass`, `access`) values('$time', '$user[id]', 'Вложения', '$time', '" . mt_rand(11111111, 99999999) . "', '$access')");
    }
    $gallery = mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `name` = 'Вложения' AND `id_user` = '$user[id]' LIMIT 1"));
    $name = mysql_real_escape_string(esc(stripcslashes(htmlspecialchars(preg_replace('#.[^.]*$#i', NULL, $_FILES['file']['name'])))));
    if (!preg_match("#^([A-zА-я0-9-_ ])+$#ui", $name)) {
        $err[] = lang('В названии фото присутствуют запрещенные символы');
    }
    $adult = 0;
    if (isset($_POST['adult'])) {
        $adult = 1;
    }
    $msg = mysql_real_escape_string($_POST['msg']);
    $img_x = imagesx($imgc);
    $img_y = imagesy($imgc);
    if ($img_x > $set['max_upload_foto_x'] || $img_y > $set['max_upload_foto_y']) {
        $err = lang('Размер изображения превышает ограничения в') . ' ' . $set['max_upload_foto_x'] . '*' . $set['max_upload_foto_y'];
    }
    if (!isset($err)) {
        mysql_query("INSERT INTO `gallery_foto` (`id_gallery`, `name`, `ras`, `type`, `opis`, `id_user`, `adult`) values ('$gallery[id]', '$name', 'jpg', 'image/jpeg', '$msg', '$user[id]', '$adult')");
        $attach_id = mysql_insert_id();
        mysql_query("UPDATE `gallery` SET `time` = '$time' WHERE `id` = '$gallery[id]' LIMIT 1");
        if ($img_x == $img_y) {
            $dstW = 48; // ширина
            $dstH = 48; // высота 
        } elseif ($img_x > $img_y) {
            $prop = $img_x / $img_y;
            $dstW = 48;
            $dstH = ceil($dstW / $prop);
        } else {
            $prop = $img_y / $img_x;
            $dstH = 48;
            $dstW = ceil($dstH / $prop);
        }
        $screen = imagecreatetruecolor($dstW, $dstH);
        imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
        #imagedestroy($imgc);
        imagejpeg($screen, H . "sys/gallery/48/$attach_id.jpg", 90);
        @chmod(H . "sys/gallery/48/$attach_id.jpg", 0777);
        imagedestroy($screen);
        if ($img_x == $img_y) {
            $dstW = 128; // ширина
            $dstH = 128; // высота 
        } elseif ($img_x > $img_y) {
            $prop = $img_x / $img_y;
            $dstW = 128;
            $dstH = ceil($dstW / $prop);
        } else {
            $prop = $img_y / $img_x;
            $dstH = 128;
            $dstW = ceil($dstH / $prop);
        }
        $screen = imagecreatetruecolor($dstW, $dstH);
        imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
        #imagedestroy($imgc);
        $screen = img_copyright($screen); // наложение копирайта
        imagejpeg($screen, H . "sys/gallery/128/$attach_id.jpg", 90);
        @chmod(H . "sys/gallery/128/$attach_id.jpg", 0777);
        imagedestroy($screen);
        if ($img_x > 640 || $img_y > 640) {
            if ($img_x == $img_y) {
                $dstW = 640; // ширина
                $dstH = 640; // высота 
            } elseif ($img_x > $img_y) {
                $prop = $img_x / $img_y;
                $dstW = 640;
                $dstH = ceil($dstW / $prop);
            } else {
                $prop = $img_y / $img_x;
                $dstH = 640;
                $dstW = ceil($dstH / $prop);
            }
            $screen = imagecreatetruecolor($dstW, $dstH);
            imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
            #imagedestroy($imgc);
            imagejpeg($screen, H . "sys/gallery/640/$attach_id.jpg", 90);
            imagedestroy($screen);
            imagejpeg($imgc, H . "sys/gallery/foto/$attach_id.jpg", 90);
            @chmod(H . "sys/gallery/foto/$attach_id.jpg", 0777);
        } else {
            imagejpeg($imgc, H . "sys/gallery/640/$attach_id.jpg", 90);
            imagejpeg($imgc, H . "sys/gallery/foto/$attach_id.jpg", 90);
            @chmod(H . "sys/gallery/foto/$attach_id.jpg", 0777);
        }
        @chmod(H . "sys/gallery/640/$attach_id.jpg", 0777);
        imagedestroy($imgc);
    }
}