Вход Регистрация
Файл: mail/inc/attachments/photo.act.php
Строк: 23
<?php 

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'])))
{
    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`, `privat`, `privat_komm`) values('$time', '$user[id]', 'Вложения', '$time', '" . mt_rand(11111111, 99999999) . "', '2', '2')");
    }
    
    
$gallery = mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `name` = 'Вложения' AND `id_user` = '$user[id]' LIMIT 1"));
    
    
$name = my_esc(esc(stripcslashes(htmlspecialchars(preg_replace('#.[^.]*$#i', NULL, $_FILES['file']['name']))))); 

    if (!
preg_match("#^([A-zА-я0-9-_ ])+$#ui", $name)) {
        
$err[] = 'В названии фото присутствуют запрещенные символы';
    }
    
    
$adult = 0;
    if (isset(
$_POST['adult'])) {
        
$adult = 1;
    }
    
    
$msg = my_esc($_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 = 'Размер изображения превышает ограничения в '.$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`, `metka`, `time`) values ('$gallery[id]', '$name', 'jpg', 'image/jpeg', '$msg', '$user[id]', '$adult', '$time')");
        
        
$attach_id = mysql_insert_id();
        
        
mysql_query("UPDATE `gallery` SET `time` = '$time' WHERE `id` = '$gallery[id]' LIMIT 1");

        
resizePhoto($attach_id, 48);
        
resizePhoto($attach_id, 128);
        
        if (
$img_x > 640 || $img_y > 640) {
              
resizePhoto($attach_id, 640);
        } else {
              
imagejpeg($imgc, H.'sys/gallery/640/' . $attach_id . '.jpg', 90);
        }
        @
chmod(H.'sys/gallery/640/' . $attach_id . '.jpg', 0666);

          
imagejpeg($imgc, H.'sys/gallery/foto/' . $attach_id . '.jpg', 90);
          @
chmod(H.'sys/gallery/foto/' . $attach_id . '.jpg', 0666);
        
imagedestroy($imgc);

        @
crop(H.'sys/gallery/640/' . $attach_id . '.jpg', H.'sys/gallery/50/' . $attach_id . '.tmp.jpg');
        @
resize(H.'sys/gallery/50/' . $attach_id . '.tmp.jpg', H.'sys/gallery/50/' . $attach_id . '.jpg', 50, 50);

        @
chmod(H.'sys/gallery/50/' . $attach_id . '.jpg', 0666);
        @
unlink(H.'sys/gallery/50/' . $attach_id . '.tmp.jpg');      
    }
}
Онлайн: 0
Реклама