<?php
include ("inc/inc_common.php");
if ($action == "upload")
{
    if (strtolower(substr("$file_name", -3)) != "jpg" AND strtolower(substr("$file_name", -3)) != "gif")
    {
        print "gif or jpg only - use your back button.";
        exit;
    }
    $pathonserver = "images/";
    $folder = "user/";
    $fileonserver = $pathonserver.$folder.$file_name;
    while (file_exists($fileonserver))
    {
        $rand = rand(0, 9);
        $file_name = $rand.$file_name;
        $fileonserver = $pathonserver.$folder.$file_name;
    }

    copy($file, $fileonserver);
    unlink($file);

    $query = "UPDATE $userstable SET strAvatar = '$fileonserver' WHERE strName = '$gfcookie[1]'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );

    header("Location: editprofile.php");
    exit;
}
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");
include ("inc/inc_forumname.php");
if (!isset($gfcookie[1]))
{
    header("Location: index.php");
    exit;
}
$page = "Upload Avatar";
$pagelink = $file;
include("inc/inc_setonline.php");
$title = "Upload Your Own Avatar";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
print "<center><br><br><br><br><br> <table border=1 cellpadding=0 cellspacing=0 bordercolor=\"$bordercolor\" width=\"60%\" bgcolor=\"$fgcolour\"><tr><td><br><table border=0 width=\"100%\" cellpadding=0 cellspacing=0>
<tr><td width=\"100%\" align=\"center\">";


print "<form method=\"POST\" action=\"uploadavatar.php\" ENCTYPE=\"multipart/form-data\"><font size=$fontsize>
<br>
Avatar Address On Your PC <input type=\"file\" name=\"file\" style=\"background-image: url('images/textbox_background.gif')\">
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\">
<br><br><input type=\"submit\" value=\"Upload\">
<input type=\"hidden\" value=\"upload\" name=\"action\"></form><br></td></tr></table></td></tr></table>
<br><br><br>";

include("inc/inc_footer.php");
?>
