<?php
session_start();
$uploadedFile = $_FILES["file"];
$filename = pathinfo($uploadedFile["name"], PATHINFO_FILENAME); 
$FileExt=  pathinfo($uploadedFile["name"], PATHINFO_EXTENSION);
$folder="uploads";
$folder_root=$_SERVER['HTTP_HOST']."/ftp";

   foreach($_POST as $key => $value):
	   //  echo $key .' : ' . $value.'<br>';
		$value=str_replace("'", "\'", $value);
		$value=str_replace('"', '\"', $value);
		if ($key=='folder'){$folder=$value;}
		if ($key=='filename'){$filename=$value;}
	//	if ($key=='FileExt'){$FileExt=$value;}
	//	if ($key=='IDc'){$IDc=$value;}
   endforeach;
 
$TargetFolder=$folder_root."/".$folder."/" ;
    $filename=$filename;
     $FileExt=$FileExt;
 
if(isset($_SESSION['FTP_FOLDER'])){
	$NameOfFolder=$_SESSION['FTP_FOLDER'];
	$TargetFolder=$_SESSION[$NameOfFolder]."/".$folder;
}
else{
	$TargetFolder= $folder;
}	
 
if(!is_dir($TargetFolder )) {
    mkdir($TargetFolder);
}
 
$TargetName= "$TargetFolder/$filename.$FileExt"; 
 
 
 move_uploaded_file($uploadedFile['tmp_name'], $TargetName);
 echo $uploadedFile["name"]." was uploaded  " . $TargetName . " | " . $TargetFolder . "=>".$_SESSION['FTP_FOLDER'];

?>

