<?php
session_start();

include "../phpconfig/config.php";
include "../phpconfig/valida_login.php";
include "../phpconfig/funcoes.php";
include "../phpconfig/slugfy.php";
include '../phpconfig/resize.php';    //Classe de resige GD2
include '../phpconfig/genpass.php';   //Geração de senhas


$nome = $_POST['nome'];
$link = $_POST['link'];
// $categoria = $_POST['categoria'];
// $serv = $_POST['servicos'];
$uploadDir = sti('doc_root').sti('up');

$img = $_FILES['imagem'];

$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions

if (!empty($img)) {
	$tempFile   = $img['tmp_name'];

	$arch = slugfyUp($img['name']);
	$name = simplesPass(array(1,0,1,0),4)."-".$arch;
	$targetFile = $uploadDir.$name;
	// Validate the filetype
	$fileParts = pathinfo($img['name']);
	if (in_array(strtolower($fileParts['extension']), $fileTypes)) {

		move_uploaded_file($tempFile, $targetFile);

		$resizeObj = new resize($targetFile);

		// Resize image (options: exact, portrait (pela lagura), landscape(pela altura), auto, crop)
	
		$resizeObj -> resizeImage(300, 300, 'crop');
		$resizeObj -> saveImage($uploadDir.'amostra-'.$name);
	


	}
}

mysql_query("INSERT INTO clientes(nome, marca, link) VALUES ('$nome', '$name', '$link')", $con) or die(mysql_error());


  
header("location:index.php");