<?php
//Created by ARDORA www.webardora.net
//ardoraPoster - uploadImaPro.php
$_SERVER["HTTP_REFERER"]="introDatos.php";
session_start();
include_once ("para.php");include_once ("../".uName."/".uName."_lib.php");
$slogin_noauthpage = 0;$slogin_pagetitle = "";session_cache_limiter("nocache,private");ini_set("memory_limit","80M");
$folderGroup=$_GET["folderG"];$indi=$_GET["indi"];$indi=(int)$indi;$path ="../".folderWork;
if ($indi==0){$contador=0;
  while (file_exists($path.$slogin_Username."_".$contador.".txt")){$contador++;}}
 else{$contador=$indi-1;}
$comentario="thumbnail";
$alternativo=""; 
$url="";
$nomeArquivo=$slogin_Username."_".$contador;
if ($indi>0){ $arquivo = file($path.$nomeArquivo.".txt"); $nomeImaxen=$arquivo[4];}
else{$nomeImaxen="";}
error_reporting(E_ALL);
$mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png","image/x-png");
$foto_nome = $_FILES["imaxenProper"]["name"]; $foto_tipo = $_FILES["imaxenProper"]["type"];
$foto_tmp = $_FILES["imaxenProper"]["tmp_name"]; $foto_tam = $_FILES["imaxenProper"]["size"];
$nameThumb="";
if ($foto_nome != "" AND $foto_tam != 0){
if(!in_array($foto_tipo, $mimetypes)) die("File type not allowed");
switch($foto_tipo) {
 case $mimetypes[0]:
 case $mimetypes[1]:
 $img = imagecreatefromjpeg($foto_tmp); break;
 case $mimetypes[2]:
 $img = imagecreatefromgif($foto_tmp);break;
 case $mimetypes[3]:
 case $mimetypes[4]:
    $img = imagecreatefrompng($foto_tmp);break;
}
$datos = getimagesize($foto_tmp);
$anchoPeque = round(75*$datos[0]/$datos[1]);
$imaPeque = imagecreatetruecolor($anchoPeque,75);
imagecopyresized($imaPeque, $img, 0, 0, 0, 0, $anchoPeque,75, $datos[0], $datos[1]);
switch($foto_tipo) {
   case $mimetypes[0]:
   case $mimetypes[1]:
   imagejpeg($imaPeque,$path.$folderGroup."/thumb/".$nomeArquivo.".jpg");
   $nameThumb=$path.$folderGroup."/thumb/".$nomeArquivo.".jpg";
   echo("success".$path.$folderGroup."/thumb/".$nomeArquivo.".jpg"); break;
   case $mimetypes[2]:
   imagegif($imaPeque,$path.$folderGroup."/thumb/".$nomeArquivo.".gif");
   $nameThumb=$path.$folderGroup."/thumb/".$nomeArquivo.".gif";
   echo("success".$path.$folderGroup."/thumb/".$nomeArquivo.".gif");break;
   case $mimetypes[3]:
   imagepng($imaPeque,$path.$folderGroup."/thumb/".$nomeArquivo.".png");
   $nameThumb=$path.$folderGroup."/thumb/".$nomeArquivo.".png";
   echo("success".$path.$folderGroup."/thumb/".$nomeArquivo.".png"); break;
}
@unlink($foto_tmp); @unlink($imaPeque);
$ar=fopen($path.$nomeArquivo.".txt","w") or die("no se pudo crear el archivo");
fputs($ar,$slogin_Username); fputs($ar,"\n"); fputs($ar,"IMAGE"); fputs($ar,"\n");
fputs($ar,trim($comentario)); fputs($ar,"\n"); fputs($ar,trim($alternativo)); fputs($ar,"\n");
fputs($ar,$url); fputs($ar,"\n"); fputs($ar,trim($nomeImaxen)); fputs($ar,"\n"); fclose($ar); 
}
$xml = new DOMDocument('1.0', 'utf-8');$xml->formatOutput = true;$xml->preserveWhiteSpace = false;
$folG="../".folderWork.$_GET["folderG"];$xml->load("../".folderWork."/foldersWork.xml");$nodes=$xml->getElementsByTagName("folder");
for ($i = 0; $i < $nodes->length; $i++) {
	$back=$xml->getElementsByTagName("folder")->item($i);
	$fol=$back->getElementsByTagName("folderName")->item(0);
	$folId=(string) $fol->nodeValue;
	if ($folId==$folG){
		$thumb=$back->getElementsByTagName("thumb")->item(0);
		$title=$back->getElementsByTagName("title")->item(0);
		if ($nameThumb!=""){$thumb->nodeValue=$nameThumb;}
		$title->nodeValue=$_POST["comentaProper"];
	}	
}
$xml->save("../".folderWork."/foldersWork.xml");
?>
