<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
require_once( "../functions.php" );
session_start();
if (!Beveiliging()){
    header ( "location: ../index.php" );
} else {
	include_once("adminfunctions.inc");
	require_once "../../includes/imagefunctions.inc" ;

	$valid = "yes" ;
	$allowed_filetypes = array('.jpg','.gif','.png');
	$max_filesize = "1048576" ;
	$upload_path = $rootpath."uploads/category/" ;



	if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
		$name = $_FILES['cat_edit_thumb']['name'];
		$size = $_FILES['cat_edit_thumb']['size'];
		$ext = substr($name, strpos($name,'.'), strlen($name)-1);


		$catname = str_replace(" ", "-", trim($_POST['cat_edit_name'])).".jpg" ;



		if(!in_array($ext,$allowed_filetypes)) {
			$valid = "no" ;
			echo "<p>Thumb filetype is not allowed, only jpg, gif, png are allowed.</p>" ;
		}
		if(filesize($_FILES['emthumbe']['tmp_name']) >= $max_filesize) {
			$valid = "no" ;
			echo "<p>Thumb filesize is to high, max allowed is 1MB</p>" ;
		}


		if ($valid == "yes") {
			if(move_uploaded_file($_FILES['cat_edit_thumb']['tmp_name'],$upload_path . $name)) {
				createThumb($name, "160", "226", $rootpath."uploads/category/", $catname);
				if (file_exists($rootpath."uploads/category/".$catname))  {
					unlink($upload_path . $name) ;
					echo "<img src='".$sitepath."uploads/category/".$catname."' >";
				}
			}
		}

	}






}

?>