<?
session_name('portal_absa');
session_start();
require "../../conexion/conectar.php";
include "../../libs/funciones.php";

$rutaInFile = getINI("RUTAALMACEN=","../../config.ini");

conectar();
	if(isset($_FILES["myfile"]))
	{
		$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
		{
		
			$fileName = str_replace(" ","",$_FILES["myfile"]["name"]);
			
			$extension = end(explode(".",$fileName));
			
			$fileName = getBaseName($fileName);
			
			$output_dir=$rutaInFile;
			
			if(!is_dir($output_dir)){
				mkdir($output_dir,777,true);
			}
			
			move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName."_".$_GET['sufijoName'].".".$extension);
			
			$ret[]= $fileName;
		}
	}
	
desconectar();

function getBaseName($file){
	$archivo = explode(".",$file);
	$fileName="";
	for($i=0; $i < (count($archivo)-1); $i++){
		if(($i-1) < (count($archivo)-3)){
			$fileName.=$archivo[$i].".";	
		}else{
			$fileName.=$archivo[$i];	
		}
	}
	return $fileName;
}
?>