View file xmyx.ru/user/feed/files.php

File size: 19.88Kb
<?

/*
 * Author - Tw1nGo
 * VK - https://vk.com/tw1ngo93
*/

define("H", $_SERVER["DOCUMENT_ROOT"].'/');
include_once H.'sys/inc/start.php';
include_once H.'sys/inc/compress.php';
include_once H.'sys/inc/sess.php';
include_once H.'sys/inc/settings.php';
include_once H.'sys/inc/db_connect.php';
include_once H.'sys/inc/ipua.php';
include_once H.'sys/inc/fnc.php';
include_once H.'sys/inc/user.php';

if (isset($user)) {
    $ank['id'] = $user['id'];
}
if (isset($_GET['id'])) {
    $ank['id'] = intval($_GET['id']);
}
if (!isset($_GET['id']) || !isset($ank) || $ank['id'] <= 0 || !isset($user))
{
    header("Location: /");
    exit;
}


$set['title'] = "Редактирование вложений";
include_once H.'sys/inc/thead.php';

// Конфигурационный файл
require H.'wall/config.php';

shapka_VK(true, '/feed?act=add', 'Новая запись');



if (isset($_POST['cfms']))
{
    if ((isset($_FILES['file_1']) && isset($_FILES['file_1']['tmp_name'])) || (isset($_FILES['file_2']) && isset($_FILES['file_2']['tmp_name'])) || (isset($_FILES['file_3']) && isset($_FILES['file_3']['tmp_name'])))
    {
        if (isset($_FILES['file_1']) && isset($_FILES['file_1']['tmp_name']))
        {
            $file = esc(stripcslashes(htmlspecialchars($_FILES['file_1']['name'])));
            $file = preg_replace('(\#|\?)', NULL, $file);
            $name = preg_replace('#\.[^\.]*$#', NULL, $file);
            if (!isset($name) || $name == NULL)
            {
                $name = 'File';
            }
            $ras = strtolower(preg_replace('#^.*\.#', NULL, $file));
            $type = $_FILES['file_1']['type'];
            if (($ras == 'png' || $ras == 'jpg' || $ras == 'jpeg' || $ras == 'gif') && $imgc = @imagecreatefromstring(file_get_contents($_FILES['file_1']['tmp_name'])))
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '1', 'jpg', '".$time."')");
                $id_f = mysql_insert_id();
                $img_x = imagesx($imgc);
                $img_y = imagesy($imgc);
                if ($img_x > 500 || $img_y > 500)
                {
                    if ($img_x == $img_y)
                    {
                        $dstW = 500;
                        $dstH = 500;
                    }
                    else if ($img_x > $img_y)
                    {
                        $prop = $img_x/$img_y;
                        $dstW = 500;
                        $dstH = ceil($dstW/$prop);
                    } else {
                        $prop = $img_y/$img_x;
                        $dstH = 500;
                        $dstW = ceil($dstH/$prop);
                    }
                } else {
                    $dstW = $img_x;
                    $dstH = $img_y;
                }
                $screen = imagecreatetruecolor($dstW, $dstH);
                imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
                imagedestroy($imgc);
                imagejpeg($screen, H.'files/wall/files/others/'.$id_f.'.jpg');
                imagedestroy($screen);
                chmod(H.'files/wall/files/others/'.$id_f.'.jpg', 0777);
            }
            else if ($ras == 'mp4' || $ras == 'avi' || $ras == 'flv')
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '2', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_1']['tmp_name'], H.'files/wall/files/others/'.$id_f.'.'.$ras.''))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
                if (class_exists('ffmpeg_movie'))
                {
                    if ($media = new ffmpeg_movie(H.'files/wall/files/others/'.$id_f.'.'.$ras))
                    {
                        $k_frame = intval($media->getFrameCount());
                        $w = $media->GetFrameWidth();
                        $h = $media->GetFrameHeight();
                        $ff_frame = $media->getFrame(intval($k_frame/2));
                        if (!$ff_frame)
                        {
                            $ff_frame = $media->getFrame('2');
                        }
                        if ($ff_frame)
                        {
                            $gd_image = $ff_frame->toGDImage();
                            if ($gd_image)
                            {
                                $des_img = imagecreatetruecolor($w, $h);
                                $s_img = $gd_image;
                                imagecopyresampled($des_img, $s_img, 0, 0, 0, 0, $w, $h, $w, $h);
                                imagegif($des_img,H."files/wall/files/video/".$id_f.".gif");
                                chmod(H."files/wall/files/video/".$id_f.".gif", 0777);
                                imagedestroy($des_img);
                                imagedestroy($s_img);
                            }
                        }
                    }
                }
                if (!is_file(H."files/wall/files/video/".$id_f.".gif"))
                {
                    unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            }
            else if ($ras == 'mp3' || $ras == 'ogg')
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '3', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_1']['tmp_name'], H.'files/wall/files/others/'.$id_f.'.'.$ras.''))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
                if (class_exists('ffmpeg_movie'))
                {
                    if ($media = new ffmpeg_movie(H.'files/wall/files/others/'.$id_f.'.'.$ras))
                    {
                        // Ждите обновление ;)
                    } else {
                        unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                        mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                    }
                } else {
                    unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            } else {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '4', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_1']['tmp_name'], H.'files/wall/files/dat/'.$id_f.'.dat'))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            }
        }
        if (isset($_FILES['file_2']) && isset($_FILES['file_2']['tmp_name']))
        {
            $file = esc(stripcslashes(htmlspecialchars($_FILES['file_2']['name'])));
            $file = preg_replace('(\#|\?)', NULL, $file);
            $name = preg_replace('#\.[^\.]*$#', NULL, $file);
            if (!isset($name) || $name == NULL)
            {
                $name = 'File';
            }
            $ras = strtolower(preg_replace('#^.*\.#', NULL, $file));
            $type = $_FILES['file_2']['type'];
            if (($ras == 'png' || $ras == 'jpg' || $ras == 'jpeg' || $ras == 'gif') && $imgc = @imagecreatefromstring(file_get_contents($_FILES['file_2']['tmp_name'])))
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '1', 'jpg', '".$time."')");
                $id_f = mysql_insert_id();
                $img_x = imagesx($imgc);
                $img_y = imagesy($imgc);
                if ($img_x > 500 || $img_y > 500)
                {
                    if ($img_x == $img_y)
                    {
                        $dstW = 500;
                        $dstH = 500;
                    }
                    else if ($img_x > $img_y)
                    {
                        $prop = $img_x/$img_y;
                        $dstW = 500;
                        $dstH = ceil($dstW/$prop);
                    } else {
                        $prop = $img_y/$img_x;
                        $dstH = 500;
                        $dstW = ceil($dstH/$prop);
                    }
                } else {
                    $dstW = $img_x;
                    $dstH = $img_y;
                }
                $screen = imagecreatetruecolor($dstW, $dstH);
                imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
                imagedestroy($imgc);
                imagejpeg($screen, H.'files/wall/files/others/'.$id_f.'.jpg');
                imagedestroy($screen);
                chmod(H.'files/wall/files/others/'.$id_f.'.jpg', 0777);
            }
            else if ($ras == 'mp4' || $ras == 'avi' || $ras == 'flv')
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '2', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_2']['tmp_name'], H.'files/wall/files/others/'.$id_f.'.'.$ras.''))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
                if (class_exists('ffmpeg_movie'))
                {
                    if ($media = new ffmpeg_movie(H.'files/wall/files/others/'.$id_f.'.'.$ras))
                    {
                        $k_frame = intval($media->getFrameCount());
                        $w = $media->GetFrameWidth();
                        $h = $media->GetFrameHeight();
                        $ff_frame = $media->getFrame(intval($k_frame/2));
                        if (!$ff_frame)
                        {
                            $ff_frame = $media->getFrame('2');
                        }
                        if ($ff_frame)
                        {
                            $gd_image = $ff_frame->toGDImage();
                            if ($gd_image)
                            {
                                $des_img = imagecreatetruecolor($w, $h);
                                $s_img = $gd_image;
                                imagecopyresampled($des_img, $s_img, 0, 0, 0, 0, $w, $h, $w, $h);
                                imagegif($des_img,H."files/wall/files/video/".$id_f.".gif");
                                chmod(H."files/wall/files/video/".$id_f.".gif", 0777);
                                imagedestroy($des_img);
                                imagedestroy($s_img);
                            }
                        }
                    }
                }
                if (!is_file(H."files/wall/files/video/".$id_f.".gif"))
                {
                    unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            }
            else if ($ras == 'mp3' || $ras == 'ogg')
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '3', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_2']['tmp_name'], H.'files/wall/files/others/'.$id_f.'.'.$ras.''))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
                if (class_exists('ffmpeg_movie'))
                {
                    if ($media = new ffmpeg_movie(H.'files/wall/files/others/'.$id_f.'.'.$ras))
                    {
                        // Ждите обновление ;)
                    } else {
                        unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                        mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                    }
                } else {
                    unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            } else {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '4', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_2']['tmp_name'], H.'files/wall/files/dat/'.$id_f.'.dat'))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            }
        }
        if (isset($_FILES['file_3']) && isset($_FILES['file_3']['tmp_name']))
        {
            $file = esc(stripcslashes(htmlspecialchars($_FILES['file_3']['name'])));
            $file = preg_replace('(\#|\?)', NULL, $file);
            $name = preg_replace('#\.[^\.]*$#', NULL, $file);
            if (!isset($name) || $name == NULL)
            {
                $name = 'File';
            }
            $ras = strtolower(preg_replace('#^.*\.#', NULL, $file));
            $type = $_FILES['file_3']['type'];
            if (($ras == 'png' || $ras == 'jpg' || $ras == 'jpeg' || $ras == 'gif') && $imgc = @imagecreatefromstring(file_get_contents($_FILES['file_3']['tmp_name'])))
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '1', 'jpg', '".$time."')");
                $id_f = mysql_insert_id();
                $img_x = imagesx($imgc);
                $img_y = imagesy($imgc);
                if ($img_x > 500 || $img_y > 500)
                {
                    if ($img_x == $img_y)
                    {
                        $dstW = 500;
                        $dstH = 500;
                    }
                    else if ($img_x > $img_y)
                    {
                        $prop = $img_x/$img_y;
                        $dstW = 500;
                        $dstH = ceil($dstW/$prop);
                    } else {
                        $prop = $img_y/$img_x;
                        $dstH = 500;
                        $dstW = ceil($dstH/$prop);
                    }
                } else {
                    $dstW = $img_x;
                    $dstH = $img_y;
                }
                $screen = imagecreatetruecolor($dstW, $dstH);
                imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
                imagedestroy($imgc);
                imagejpeg($screen, H.'files/wall/files/others/'.$id_f.'.jpg');
                imagedestroy($screen);
                chmod(H.'files/wall/files/others/'.$id_f.'.jpg', 0777);
            }
            else if ($ras == 'mp4' || $ras == 'avi' || $ras == 'flv')
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '2', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_3']['tmp_name'], H.'files/wall/files/others/'.$id_f.'.'.$ras.''))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
                if (class_exists('ffmpeg_movie'))
                {
                    if ($media = new ffmpeg_movie(H.'files/wall/files/others/'.$id_f.'.'.$ras))
                    {
                        $k_frame = intval($media->getFrameCount());
                        $w = $media->GetFrameWidth();
                        $h = $media->GetFrameHeight();
                        $ff_frame = $media->getFrame(intval($k_frame/2));
                        if (!$ff_frame)
                        {
                            $ff_frame = $media->getFrame('2');
                        }
                        if ($ff_frame)
                        {
                            $gd_image = $ff_frame->toGDImage();
                            if ($gd_image)
                            {
                                $des_img = imagecreatetruecolor($w, $h);
                                $s_img = $gd_image;
                                imagecopyresampled($des_img, $s_img, 0, 0, 0, 0, $w, $h, $w, $h);
                                imagegif($des_img,H."files/wall/files/video/".$id_f.".gif");
                                chmod(H."files/wall/files/video/".$id_f.".gif", 0777);
                                imagedestroy($des_img);
                                imagedestroy($s_img);
                            }
                        }
                    }
                }
                if (!is_file(H."files/wall/files/video/".$id_f.".gif"))
                {
                    unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            }
            else if ($ras == 'mp3' || $ras == 'ogg')
            {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '3', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_3']['tmp_name'], H.'files/wall/files/others/'.$id_f.'.'.$ras.''))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
                if (class_exists('ffmpeg_movie'))
                {
                    if ($media = new ffmpeg_movie(H.'files/wall/files/others/'.$id_f.'.'.$ras))
                    {
                        // Ждите обновление ;)
                    } else {
                        unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                        mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                    }
                } else {
                    unlink(H.'files/wall/files/others/'.$id_f.'.'.$ras);
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            } else {
                mysql_query("INSERT INTO `user_wall_files` (`id_user`, `name`, `type`, `ras`, `time`) values ('".$user['id']."', '".my_esc($name)."', '4', '".$ras."', '".$time."')");
                $id_f = mysql_insert_id();
                if (!@copy($_FILES['file_3']['tmp_name'], H.'files/wall/files/dat/'.$id_f.'.dat'))
                {
                    mysql_query("DELETE FROM `user_wall_files` WHERE `id` = '".$id_f."' LIMIT 1");
                }
            }
        }
   
        header("Location: /feed?act=add");
       
        exit;
    } else {
        $err = 'Выберите файлы!';
    }
}
err();
?>
<div class="pcont fit_box bl_cont">
<h4 class="slim_header">Выберите файлы</h4>
<div class="form_item upload_form">
  <form action="/attach<?= $ank['id']?>" method="post" enctype="multipart/form-data">
    <div class="upload_row"><input class="upload_input" name="file_1" type="file"></div>
    <div class="upload_row"><input class="upload_input" name="file_2" type="file"></div>
    <div class="upload_row"><input class="upload_input" name="file_3" type="file"></div>
    <div class="upload_row">
      <input class="button" value="Загрузить" name="cfms" type="submit">
      <a class="near_btn" href="/feed?act=add">Назад</a>
    </div>
  </form>
</div>
</div>
<?

include_once H.'sys/inc/tfoot.php';

?>