[insert_php]
//require ‘DropboxUploader-master/DropboxUploader.php’;
require_once “dropbox-sdk/Dropbox/autoload.php”;
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile(“app-info.json”);
$webAuth = new dbx\WebAuthNoRedirect($appInfo, “PHP-Example/1.0″);
$accessToken =”MpFWCdgYbI8AAAAAAAIMNIEwIfZ3iWSOpnYLbgSCa-IBuUTrG5BPalUkex98iyCz”;
$dbxClient = new dbx\Client($accessToken, “PHP-Example/1.0”);
$db = new stdClass();
$db->host = ‘localhost’;
$db->usr = ‘uipadmin_boca’;
$db->pass =’connected5′ ;
$db->dbname =’uipadmin_boca’;

$conn = new mysqli($db->host, $db->usr, $db->pass, $db->dbname);
//$uploader = new DropboxUploader(‘federickramos@yahoo.es’,’Griveo7′);

//GET VARS
$target_dir = “fotos”;
$nombre = $_POST[‘nombre’];
$apellido = $_POST[‘apellido’];
$dni = $_POST[‘dni’];
$email = $_POST[’email’];
$historia = $_POST[‘historia’];
$sexo = $_POST[‘sexo’];
$telefono = $_POST[‘telefono’] != null ? $_POST[‘telefono’] : null;

$temp = explode(“.”,$_FILES[“foto”][“name”]);
$newfilename = $dni.’-‘.$apellido.’-‘.$nombre.’.jpg’;
$tmp = $_FILES[“foto”][“tmp_name”];
$target_file = $target_dir .’/’.$newfilename;
$f = fopen($tmp, “rb”);

$SQL1 = “SELECT count(*) FROM usuarios WHERE dni = ‘$dni'”;

$result = $conn->query($SQL1);
$count = $result->fetch_row();
$flag = $count[0];

//$dbxClient->uploadFile(‘/’ . $tmp, dbx\WriteMode::add(), $f);
//$uploader->upload($tmp, ‘public/FOTOBOSTERA’, $newfilename);

if($flag==0)
{
$SQL =”INSERT INTO usuarios (nombre, apellido, dni, email, historia, sexo, telefono)
VALUES (‘$nombre’, ‘$apellido’, ‘$dni’, ‘$email’, ‘$historia’, ‘$sexo’, ‘$telefono’)”;
$result = $conn->query($SQL);
$id = $conn->insert_id;
$conn->close();
//Upload Script
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST[“submit”])) {
$check = getimagesize($_FILES[“foto”][“tmp_name”]);
if($check !== false) {
echo “File is an image – ” . $check[“mime”] . “.”;
$uploadOk = 1;
} else {
//echo “El archivo no es una imagen valida.”;
header(“Location: http://uip.com.ar/fotobostera/error.html”);
die();
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo “Ya existe una imagen con ese nombre.”;
$uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
header(“Location: http://uip.com.ar/fotobostera/error.html”);
die();
//echo “UPS! Parece que hubo un error inesperado.”;
// if everything is ok, try to upload file
} else {
try /*if (move_uploaded_file($tmp, “$target_dir/$newfilename”)) */{
$dbxClient->uploadFile(‘/’ . $newfilename, dbx\WriteMode::add(), $f);
header(“Location: http://uip.com.ar/fotobostera/success.html”);
die();
// echo “Tu Foto ha sido subida. Ya estas participando!”;
} catch(Exception $e) {
header(“Location: http://uip.com.ar/fotobostera/error.html”);
die();
//echo “UPS! Ocurrio un error al subir tu foto. Intentalo de nuevo mas tarde.”;
}
}
}else {
header(“Location: http://uip.com.ar/fotobostera/once.html”);
die();
}//echo “Solo podes participar una vez. Suerte!”;

[/insert_php]