<style type="text/css">
.waiting { cursor: wait; }

 p {
     border:1px solid blue;
	 border-radius: 5px;
	 font-size:1.5em;
	 font-weight:600;
	 color:blue;
	 
	 margin:10px;
	 padding:20px;
	 text-align:center;
	 }

.btn_blue {margin-top:0px !important; margin-bottom:20px !important;}	
 
 </style>
<style>
.loader {
  border: 16px solid #f3f3f3; border-radius: 50%; border-top: 16px solid #3498db;
  width: 120px;  height: 120px;
  -webkit-animation: spin 2s linear infinite; /* Safari */
  animation: spin 2s linear infinite;
/* ==== CENTER PAGE ====*/  
  margin: 0; position: absolute; top: 50%; left: 50%;
  -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%);
  top: 40%;  -ms-transform: translateY(-30%); transform: translateY(-30%); 
}

/* Safari */
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>
 
<div class="loader"></div>

<body >

<?php

session_start();
#error_reporting(E_ALL);


$myVal=""; $server_folder=""; $local_file="";
$countfiles=0; 
$filename="";
$filesize=0;
$i=0;
# ============================

$server_folder=$_GET['sfolder'];
//$command=$_GET['c'];
$local_file= $_FILES['myfile'] ;
 
$s= "server_folder=".$server_folder." <br> ";

# var_dump($local_file);
 
# echo"<br>===================== <br>"; 
#	var_dump($local_file['name']);
# echo"<br>===================== <br>"; 
 
if (isset($_FILES['myfile'])) {
	
  $local_file2 = $_FILES['myfile'] ;  
 $countfiles=count($local_file2['name']);
 
#echo "Files No: " . $countfiles ."<br>" ;
#echo"===================== <br>";
	for ($i = 0; $i <= $countfiles-1 ; $i=$i+1) {
    	$filename  = $local_file['name'][$i] ;
		 $filesize = $local_file['size'][$i];
		 $tmp_name = $local_file['tmp_name'][$i];
		     $type = $local_file['type'][$i];
		       $s .= "filename $i: $filename , size: $filesize , tmp_name: $tmp_name , type: $type <br>";
	}
	
   // Get the file extension
  //  $fileType = strtolower(pathinfo(basename($_FILES["file"]["name"]), PATHINFO_EXTENSION));
	 //$filename = strtolower( basename($_FILES["file"]["name"]) );

}	
# echo $s;

# ====================================

$ftp_server = "visualsoft.gr";
$ftp_user = "customers_user";
$ftp_pass = "P@ssw0rdFtp!";
 
$dirname = dirname($server_folder);

$m_dir = 'c:\\_visualsoft\\';
 
#$local_file = explode("/", $server_file);
//$local_file = end($local_file);
 
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
    if ( ftp_login($conn_id, $ftp_user, $ftp_pass)) 
    {
			#  echo "Connected as $ftp_user@$ftp_server\n";  
	}else{
			#  echo "Couldn't connect as $ftp_use br@$ftp_server\n";  
	}
# =====================================	
ftp_set_option($conn_id, FTP_USEPASVADDRESS, false); // set ftp option
ftp_pasv($conn_id, true); //make connection to passive mode
# =====================================  

if(!is_dir($m_dir)) {  mkdir($m_dir,0755,true); } 

$filename = strtolower( basename($local_file["name"][0])) ;
# echo $filename;

# $fp = fopen($local_file['tmp_name'][0],"r");
# $fp = fopen($m_dir.$local_file,"r");
# $local_File1=$m_dir.$local_file;
 
$server_file=$server_folder."//". $local_file['name'][0];

# =====================================   
#       PUT Files To Server
# =====================================  
	$files_ok=0;
	$files_not_ok=0;
	
	for ($i = 0; $i <= $countfiles-1 ; $i=$i+1) {
    	$filename  = $local_file['name'][$i] ;
		 $filesize = $local_file['size'][$i];
		 $tmp_name = $local_file['tmp_name'][$i];
		     $type = $local_file['type'][$i];
		   //  $s .= "filename $i: $filename , size: $filesize , tmp_name: $tmp_name , type: $type <br>";
	
	  $server_file = $server_folder."//". $filename;
	
		if (ftp_put($conn_id, $server_file, $local_file['tmp_name'][$i] ,  FTP_BINARY )) {  
				$files_ok=$files_ok+1;
				# $myVal= "Επιτυχής μεταφορά αρχείου: ". $local_file['name'][0] . ", \n στον φάκελο $m_dir";  
		}else{ 	$files_not_ok=$files_not_ok+1;
				# $myVal= "Πρόβλημα κατα την μεταφορά αρχείου: $local_file\n"; 
				}  
		 
	}



 if ($files_ok==$countfiles){ $myVal= "Όλα τα αρχεία ($files_ok), μεταφέρθηκαν στον Server επιτυχώς.";}
 if ($files_not_ok==$countfiles){ $myVal= "Πρόβλημα κατα την μεταφορά των αρχείων στο Server.";}
 
 if (!$files_ok==0 && !$files_not_ok==0 ){ 
				$myVal = "$files_ok αρχεία, μεταφέρθηκαν στον Server επιτυχώς.";
	   $myVal = $myVal . "σε $files_not_ok αρχεία, σημειώθηκε πρόβλημα στην μεταφορά στον Server.";
 }
 
 // echo '<br>' . $myVal ;	
 
# =====================================  

ftp_close($conn_id); 
 
// echo $myVal;
 
//echo '<br>';   
?>
 
<p >
 <?php echo $myVal ; ?>
</p>

<script language="JavaScript" type="text/JavaScript">
  window.history.back();
  location.reload();
</script> 