[HOME]

Path : /home/hermanostamargo/www/administracion/content/home/
Upload :
Current File : /home/hermanostamargo/www/administracion/content/home/home-upload.php

<?php
include("../../../defines.php");
$output_dir = "../../../images/";
include("../../bd-con.php");
include("../../funciones.php");	
include("vars.php");

if(isset($_FILES["myfile"]))
{
	$coleccion=$_GET["param"];
	$ret = array();

	$error =$_FILES["myfile"]["error"];
	//You need to handle  both cases
	//If Any browser does not support serializing of multiple files using FormData() 
	if(!is_array($_FILES["myfile"]["name"])) //single file
	{

		$extension = end(explode('.',$_FILES["myfile"]['name']));
		$fileName = substr($_FILES["myfile"]['name'],0,strlen($_FILES["myfile"]['name'])-(strlen($extension)+1))."-".time();
		$fileName = toAscii($fileName, "'").".jpg";
 		move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName);

		include ("../comunes/callback/modificarlafoto.php");
		$im = imagecreatefromjpeg($output_dir.$fileName);
		$resized = resizeFit($im, 700, 203);
		imagejpeg($resized,$output_dir. "thumbnail-" . $fileName);
		imagedestroy($resized);

		$im = imagecreatefromjpeg($output_dir.$fileName);
		$resized = resizeFit($im, 1024, 296);
		imagejpeg($resized,$output_dir. "med-" . $fileName);
		imagedestroy($resized);		

		$im = imagecreatefromjpeg($output_dir.$fileName);
		$resized = resizeFit($im, 1900, 550);
		imagejpeg($resized,$output_dir.$fileName);
		imagedestroy($resized);			

		//insertar en bd
		$campos = "imagen, imagen_thumb, imagen_med, leyenda_es, idfamilia";
		$valores .= "'".$fileName."',";
		$valores .= "'thumbnail-" . $fileName."',";
		$valores .= "'med-" . $fileName."',";
		$valores .= "'" . $leyenda . "',";
		$valores .= "'".$coleccion."'";
		$sql = "INSERT INTO " . $seccion . "fotos ($campos) VALUES ($valores)";
		$result_fotos = mysqli_query($conn,$sql);		

    	$ret[]= $fileName;
	}
	else  //Multiple files, file[]
	{
	  $fileCount = count($_FILES["myfile"]["name"]);
	  for($i=0; $i < $fileCount; $i++)
	  {


		$extension = end(explode('.',$_FILES["myfile"]['name'][$i]));
		$fileName = substr($_FILES["myfile"]['name'][$i],0,strlen($_FILES["myfile"]['name'][$i])-(strlen($extension)+1))."-".time();
		$fileName = toAscii($fileName, "'").".jpg";
		move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName);

		include ("../comunes/callback/modificarlafoto.php");
		$im = imagecreatefromjpeg($output_dir.$fileName);
		$resized = resizeFit($im, 350, 100);
		imagejpeg($resized,$output_dir. "thumbnail-" . $fileName);
		imagedestroy($resized);

		$im = imagecreatefromjpeg($output_dir.$fileName);
		$resized = resizeFit($im, 1024, 296);
		imagejpeg($resized,$output_dir. "med-" . $fileName);
		imagedestroy($resized);		

		$im = imagecreatefromjpeg($output_dir.$fileName);
		$resized = resizeFit($im, 1900, 550);
		imagejpeg($resized,$output_dir.$fileName);
		imagedestroy($resized);		

		//insertar en bd
		$campos = "imagen, imagen_thumb, imagen_med, leyenda_es, idfamilia";
		$valores .= "'".$fileName."',";
		$valores .= "'thumbnail-" . $fileName."',";
		$valores .= "'med-" . $fileName."',";
		$valores .= "'" . $leyenda . "',";
		$valores .= "'".$coleccion."'";
		$sql = "INSERT INTO " . $seccion . "fotos ($campos) VALUES ($valores)";
		$result_fotos = mysqli_query($conn,$sql);		

		$ret[]= $fileName;
	  }  

	
	}
    echo json_encode($ret);
 }
 ?>