$defaults = array('0.jpg', '1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg');
if (isset($session_id)) {
    $valid_formats = array("jpg", "JPG", "jpeg", "png", "x-png", "gif", "pjpeg");
    if (isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST") {
        $name = $_FILES['photo']['name'];
        $size = $_FILES['photo']['size'];
        if (strlen($name)) {
            $ext = pathinfo($name);
            if (in_array($ext['extension'], $valid_formats)) {
                if ($size < 1500 * 1500) {
                    $photo_post = 'bg_' . strtolower($infoUser->username) . "_" . $session_id . "" . _Function::randomString(5, FALSE, TRUE, FALSE) . "." . strtolower($ext['extension']);
                    $tmp = $_FILES['photo']['tmp_name'];
                    if (move_uploaded_file($tmp, $path . $photo_post)) {
                        //=============== 440 px =================//
                        $width = _Function::getWidth($path . $photo_post);
                        $height = _Function::getHeight($path . $photo_post);
                        $scale = 1;
                        $uploaded = _Function::resizeImage($path . $photo_post, $width, $height, $scale, $path . $photo_post);
                        //<=//   PHOTO LARGE     =//>
                        $photo_post_id = $photo_post;
                        //==================================================//
                        //=            * COPY FOLDER AVATAR /         *    =//
                        //==================================================//
                        if (file_exists($path . $photo_post) && isset($photo_post_id)) {
                            copy($path . $photo_post, $path_bg . $photo_post);
                            unlink($path . $photo_post);
                        }
                        //<--- IF FILE EXISTS	#2
                        //<<<-- Delete old image -->>>/
                        if (file_exists($bg_old) && $infoUser->bg != '' && !in_array($infoUser->bg, $defaults)) {
                            unlink($bg_old);
 if (strlen($name)) {
     $ext = pathinfo($name);
     if (in_array($ext['extension'], $valid_formats)) {
         if ($size < 2250 * 2250) {
             $randomHash = _Function::randomString(5, FALSE, TRUE, FALSE);
             $photo_post = 'cover_' . strtolower($infoUser->username) . "_" . $session_id . "" . $randomHash . "." . strtolower($ext['extension']);
             $photo_large = 'large_cover_' . strtolower($infoUser->username) . "_" . $session_id . "" . $randomHash . "." . strtolower($ext['extension']);
             $tmp = $_FILES['photo']['tmp_name'];
             $dimensionsImage = getimagesize($tmp);
             $widthImage = $dimensionsImage[0];
             $heightImage = $dimensionsImage[1];
             if ($widthImage >= 400 && $heightImage >= 200) {
                 if (move_uploaded_file($tmp, $path . $photo_large)) {
                     //=============== Image Large =================//
                     $width = _Function::getWidth($path . $photo_large);
                     $height = _Function::getHeight($path . $photo_large);
                     $max_width = '1500';
                     if ($width < $height) {
                         $max_width = '800';
                     }
                     if ($width > $max_width) {
                         $scale = $max_width / $width;
                         $uploaded = _Function::resizeImage($path . $photo_large, $width, $height, $scale, $path . $photo_large);
                     } else {
                         $scale = 1;
                         $uploaded = _Function::resizeImage($path . $photo_large, $width, $height, $scale, $path . $photo_large);
                     }
                     _Function::resizeImageFixed($path . $photo_large, 860, 260, $path . $photo_post);
                     //<=//   PHOTO LARGE     =//>
                     $photo_post_id = $photo_post;
                     //==================================================//