Вход Регистрация
Файл: Source/pages/avatar.php
Строк: 111
<?php
/*
 * Script name: Points4Prize
 * Author: Soft Projects
 * Date created: 15/07/2015
 */

require_once 'inc/header.php';
if (!isset(
$_SESSION['logged_in'])) {
    
header('Location: /login');
    exit();
}  

?>
<body class="no-slider">
    <!-- <body class="has-top-menu"> -->
    <!-- BEGIN #slider-imgs -->
    <div id="slider-imgs">
        <div class="featured-img-box">
            <div id="featured-img-1" class="featured-img"></div>
            <div id="featured-img-2" class="featured-img invisible"></div>
            <div id="featured-img-3" class="featured-img invisible"></div>
            <div id="featured-img-4" class="featured-img invisible"></div>
        </div>
        <!-- END #slider-imgs -->
    </div>

    <!-- BEGIN #top-layer -->
    <div id="top-layer">
        <div id="header-top">
            <?php
            
require_once 'inc/header_top.php';
            
?>
        </div>
        <section id="content">
            <header id="header">
                <div id="menu-bottom">

                    <?php
                    
require_once 'inc/menu_bottom.php';
                    
?>

                </div>
                <div class="wrapper">
                    <div class="header-breadcrumbs">
 <?php                    require_once 'inc/stats.php';                    ?>
                        <ul>
                            <li><a href="index.php">Home</a></li>
                            <li>Change avatar </li>
                        </ul>
                    </div>
                </div>

            </header>
            <div id="main-box" class="full-width">
                <div id="main">
                    <div class="signup-panel">
                          <div class="left" style="width:666px;">
                            <h2><span>Change avatar </span></h2>
                            <div class="content-padding">
           <?php
                      
if (isset($_SESSION['user'], $_SESSION['pass'])) {
                        
$user str_replace(" """$_SESSION['user']);
                        
$user sprintf("%s"mysql_real_escape_string($user));
                    } else {
                        
$user str_replace(" """$_COOKIE['user']);
                        
$user sprintf("%s"mysql_real_escape_string($user));
                    }
                    
$result mysql_query("SELECT * FROM vn_users WHERE user='{$user}'") or die(mysql_error());
                    
$row mysql_fetch_array($result);
                                    
                    
                if (isset(
$_POST['updateprofile'])) {
                    
$errors = array();

                    if (empty(
$_FILES['avatar']['tmp_name']) === false) {
                        @
$file_ext strtolower(end(explode('.'$_FILES['avatar']['name'])));
                        
$allowed_ext = array('jpg''jpeg''png''gif');
                        
$maxsize 1524288//512KB
                        
$aavatar $_FILES['avatar']['tmp_name'];

                        if (
in_array($file_ext$allowed_ext) === false) {
                            
$errors[] = '<div class="info-message" style="background-color: #a24026;"> Avatar should be image.</div>';
                        }
                        if (
$_FILES['avatar']['size'] > $maxsize) {
                            
$errors[] = '<div class="info-message" style="background-color: #a24026;"> Avatar should not be greater than 512KB.</div>';
                        }
                    }

                    if (empty(
$errors)) {
                        if (
file_exists($aavatar)) {
                            
$src_size getimagesize($aavatar);
                            if (
$src_size['mime'] == 'image/jpeg') {
                                
$src_img imagecreatefromjpeg($aavatar);
                            } elseif (
$src_size['mime'] == 'image/png') {
                                
$src_img imagecreatefrompng($aavatar);
                            } elseif (
$src_size['mime'] == 'image/gif') {
                                
$src_img imagecreatefromgif($aavatar);
                            } else {
                                
$src_img false;
                            }

                            if (
$src_img != false) {
                                if (
$src_size[0] > $src_size[1]) {
                                    
$thumb_width 220;
                                    if (
$src_size[0] <= $thumb_width) {
                                        
$thumb $src_img;
                                    } else {
                                        
$new_size[0] = $thumb_width;
                                        
$new_size[1] = ($src_size[1] / $src_size[0]) * $thumb_width;

                                        
$thumb imagecreatetruecolor($new_size[0], $new_size[1]);
                                        
imagecopyresampled($thumb$src_img0000$new_size[0], $new_size[1], $src_size[0], $src_size[1]);
                                    }
                                } else {
                                    
$thumb_height 220;
                                    if (
$src_size[1] <= $thumb_height) {
                                        
$thumb $src_img;
                                    } else {
                                        
$new_size[0] = ($src_size[0] / $src_size[1]) * $thumb_height;
                                        
$new_size[1] = $thumb_height;

                                        
$thumb imagecreatetruecolor($new_size[0], $new_size[1]);
                                        
imagecopyresampled($thumb$src_img0000$new_size[0], $new_size[1], $src_size[0], $src_size[1]);
                                    }
                                }
                                
imagejpeg($thumb"uploads/avatars/{$row['id']}.jpg");
                                
                                
                                
mysql_query("UPDATE vn_users SET avatar='/uploads/avatars/{$row[id]}.jpg' WHERE id='{$row[id]}'") or die(mysql_error());
                            }
                        }
                        
                        echo 
"<div class='info-message' style='background-color: #75a226;'>
    Changes made successfully.
                        </div>"
;
                        
header("Location: /cp");
                        
                    } else {
                        echo 
"<div class='msg-error'>";
                        foreach (
$errors as $error) {
                            echo 
$error '<br />';
                        }
                        echo 
"</div>";
                    }
                }
                
                  if (empty(
$row['avatar'])) {
                    
$avatar "uploads/avatars/noavatar.png";
                } else {
                    
$avatar $row['avatar'];
                }
                
?>
                                
                                
                                
     <form style="float: left;" method="post" enctype="multipart/form-data" name="changeprofile" id="changeprofile">
                    <div style="float:left;"><h3>Avatar:</h3> <br />
                        <div style="width:220px; height:220px; border:1px dotted #545454; background:url(<?php echo $avatar?>) no-repeat center,center;"></div>
                        <input type="file" name="avatar" class="input" style="width:220px; margin-top:5px; cursor:pointer;" />
                    </div>
                    <table style="margin:0 auto; clear:both;"> 
                        <tr>
                            <td><button type="submit" name="updateprofile"  class="newdefbutton" style="width:150px;">Upload new avatar</button></td>
                        </tr>
                    </table>
                </form>
                
                
                <div style="float: right; width: 380px;">
                <h3>Rules upload an avatar:</h3>
                <br />
                <ul class="fa-ul">
                    <li><i class="fa-li fa fa-angle-double-right"></i>Avatar should not be larger than 512KB.</li>
                    <li><i class="fa-li fa fa-angle-double-right"></i>Avatar should be image.</li>
                    <li><i class="fa-li fa fa-angle-double-right"></i>Permitted formats: jpg, jpeg, png, gif.</li>
                    <li><i class="fa-li fa fa-angle-double-right"></i>Universal avatar size is 222х222.</li>
                </ul>
                
                
                
                </div>
                
                
                
                
               
                            </div>
                            </div>
                            <div class="right" style="width:245px;">
                            
                                <div class="content-padding">
                                    <div class="form-split-about">
                                    <?php
                                    
//include ads
                                    
include("inc/ads250.php");
                                    
?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clear-float"></div>
                    </div>
                </div>
                
                <div class="clear-float"></div>
            </div>
    </div>
</div>

<?php
require_once 'inc/footer.php';
?>
Онлайн: 0
Реклама