View file Spiderwap.in File Hosting/panel/ava.php

File size: 2.68Kb
<?php
require ('../sys/set.php');


if(!isset($_GET['add']) && !isset($_GET['del'])){

$smarty->assign('title','Set avatar');
$smarty->display('header.tpl');
$smarty->display('ank.ava.tpl');
$smarty->display('footer.tpl');

} elseif(isset($_GET['del'])){
if(!empty($user['ava'])){
$sql->query('UPDATE `acc` SET `ava`="" WHERE `id`="'.$user['id'].'"');
unlink($_SERVER['DOCUMENT_ROOT'].'/ava/'.$user['ava']);
	$smarty->assign('title','Finish');
	$smarty->assign('back','/panel/ava.php');
	$smarty->assign('ok','Avatar successfully removed');
	$smarty->assign('nz','Back');
	$smarty->display('header.tpl');
	$smarty->display('ok.tpl');
	$smarty->display('footer.tpl');
	} else {
	$smarty->assign('title','Error');
	$smarty->assign('error','You have not uploaded avatar');
	$smarty->assign('back','/panel/ava.php');
	$smarty->display('header.tpl');
	$smarty->display('error.tpl');
	$smarty->display('footer.tpl');

	}

} else {

class upfile {
	var $type,$name,$ext,$size,$tmp;
	function upfile($file){
	$this->type = $file['type'];
	$this->size = $file['size'];
	$this->name = str_replace('.'.$this->ext,'',$file['name']);
	$this->tmp = $file['tmp_name'];
	$this->ext = strtolower(PATHINFO($file['name'],PATHINFO_EXTENSION));
	}
}

$file = new upfile($_FILES['file']);

if(!in_array($file->ext,array('jpg','png','gif'))){
	$error = 'Avtar Format: png,gif,jpg';}
if($file->size/1024>200){
	$error = 'The maximum size of avatars 200Kb';}

if(!is_uploaded_file($file->tmp)){
	$error = 'File not uploaded';}  else {

list($w,$h) = getimagesize($file->tmp);

if($w<5 || $w>150 || $h<5 || $h>150){
	$error = 'The Minimized size of avatars 150x150';}

}


if(isset($error)){
$smarty->assign('title','Error');
$smarty->assign('error',$error);
$smarty->assign('back','/panel/ava.php');
$smarty->display('header.tpl');
$smarty->display('error.tpl');
$smarty->display('footer.tpl');
}

if(!empty($user['ava'])){
unlink('../ava/'.$user['ava']);}

if(!move_uploaded_file($file->tmp,'../ava/'.md5($user['id']).'.'.$file->ext)){
$smarty->assign('title','Error');
$smarty->assign('error','There was an error, contact your administrator');
$smarty->assign('back','/upload.php');
$smarty->display('header.tpl');
$smarty->display('error.tpl');
$smarty->display('footer.tpl');} else {

	$sql->query('UPDATE `acc` SET `ava`="'.md5($user['id']).'.'.$file->ext.'" WHERE `id`="'.$user['id'].'"');
	$smarty->assign('title','Finish');
	$smarty->assign('back','/panel/ava.php');
	$smarty->assign('ok','Avatar of successfully uploaded');
	$smarty->assign('nz','Back');
	$smarty->display('header.tpl');
	$smarty->display('ok.tpl');
	$smarty->display('footer.tpl');
}



}


?>