<?php

			if (isset($_GET['run']))
			{
				$filerun = $_GET['run'];
				if (exec("\"$filerun\""))
				{
					echo "file is running!";
					
				}
				die;
			}
			
			
				{ ///AJAX EDIT SAVE FILE	
			if (isset($_POST['editfilesave']))
			{
				$sfilename = $_POST['sfilename'];
				$sfilecontent = $_POST['sfilecontent'];
				///////FILE SAVING CODE
			}
				
			}
			
		{ ///AJAX EDIT GET	
			if (isset($_POST['ajaxeditget']))
			{
				$filename = $_POST['filename'];
				echo "<div style='' id='editorcon' class='editorcon'>";
				{////Edit Close button
				echo "<div style='' id='editorconclose' class='editorconclose'
				onclick=\"document.getElementById('editorcon').style.display='none'\"				>
				&nbsp; &nbsp; X &nbsp;&nbsp;
				</div>";
				}
				
				echo "<div style='clear:both;'> </div>";
				echo "$filename <br />";
				$filetxtc = "";
				$myfile = fopen("$filename", "r") or die("Unable to open file!");
// Output one character until end-of-file
while(!feof($myfile)) {
 $filetxtc .= fgetc($myfile);
}
fclose($myfile);
	$filetxtc = htmlspecialchars($filetxtc);		
	
				
				echo "
				<div style='overflow:auto; width:98%; height:80%;'>
				<center>
				<textarea class='edittextarea' id='edittextarea' ondblclick='alert(this.value)'>
				";
				echo $filetxtc;
				
				echo"
				
				</textarea>	
</center>				</div>
				";
				
				echo "</div>";
				
				
				die;//////ends execution	
				
			}
		}
		
	{ /// FILE DOWNLOAD	
		if (isset($_GET['download']))
			{
				$filedownload = $_GET['download'];
				
$file_directory = ""; //Name of the directory where all the sub directories and files exists
$file = $filedownload; //Get the file from URL variable
$file_array = explode('/', $file); //Try to seperate the folders and filename from the path
$file_array_count = count($file_array); //Count the result
$filename = $file_array[$file_array_count-1]; //Trace the filename
$file_path = dirname(__FILE__).'/'.$file_directory.'/'.$file; //Set the file path w.r.t the download.php... It may be different for u
if(file_exists($file_path)) {
    header("Content-disposition: attachment; filename={$filename}"); //Tell the filename to the browser
    header('Content-type: application/octet-stream'); //Stream as a binary file! So it would force browser to download
    readfile($file_path); //Read and stream the file
}
else {
    echo "Sorry, the file does not exist!";
}
				
				
				
				die;
			}}
?>
<html>
<head>
<style>
.editorcon {width:98%; height:60%; opacity:0.9;  background:white; border:2px solid grey;
position:fixed; top:5px; left:5px;
}
.editorconclose {width:40px; height:40px; background:grey; border:2px solid black; float:right;}
.editorconclose:hover {width:40px; height:40px; background:lime; border:2px solid black; float:right;}
.edittextarea {width:98%; min-width:98%; max-width:98%; height:70%;}


input[type=file]{height:20px;background:lime;}
</style>


<script type="text/javascript" src="jquery.js">
</script>
<script>

function editfile(efile, fname){
  $.post("u.php",{filename:fname, ajaxeditget:efile},function(result){
    $("#editor").html(result);
  });

}
</script>


</head>

<body>

<div id='editor'>

</div>
<h1 style="margin:0px; background:red;">File Manager</h1>
<h2>


<?php
date_default_timezone_set('Africa/Lagos');

$time = date("h:i A l, F d Y",time());

echo $time;
?>

</h2>



<?php
$t = "./";	

		//folder fuctions
			if (isset($_POST['folder']))
			{
				$t = $_POST['folder'];
				$t = trim("$t/");
					if(file_exists("$t"))
					{
						echo "folder already exist<br />";
					}
					else
					{
						if (($_POST['folder'] != "") ||  ($_POST['folder'] != " "))
							{
								
								mkdir("$t");
								echo "Folder \"$t\" created successfully! <br />";
							}
					}
			
			}
		
		else
		
		{
		$t = "./";
		}
		
		if (!isset($_POST['folder']))
			{ 
		$_POST['folder'] = "";
		}
		
		if (($_POST['folder'] == "") || ($_POST['folder'] == " ") || ($_POST['folder'] == "./"))
		
		{
		$t = "./";
		}
		//folder end

		
if(isset($_POST ["sub" ])){

$url = trim($_POST ["url" ]) ;
//echo "<script>alert('$url');</script>";
if( $url ){
$file = fopen ($url , "rb" );
if( $file ){

$directory = trim("$t/"); // Directory to upload files to.
//echo "<script>alert('$directory');</script>";
$valid_exts = array("jpg" , "zip" , "gif" , "png", "3gp" ); // default mage onlexte

$ext = end ( explode( "." , strtolower (basename( $url )))) ;

if(1<2){

if(($_POST['newname'] == "") ||  ($_POST['newname'] == " "))
{
	$filename =  basename( $url );
echo "<script>alert('no new name');</script>";

}
else{
$filename =  $_POST['newname'];
}



$newfile = fopen( $directory . $filename, "wb" ) ;
if( $newfile ){
while (!feof ( $file )){
// Write the url file to the directory.
fwrite($newfile , fread( $file , 1024 * 8 ), 1024 * 8 ) ; // writhe fi
}
echo 'File uploaded successfully! You can access the file here:' ." \n " ;
$t = $directory;
echo '' .$directory .$filename .'' ;
$root =	$_SERVER['HTTP_HOST'];
$link = "$directory$filename";
echo "&nbsp; <a href='$link'> $link </a>";
} else { echo 'Could not establish new file (' .$directory. $filename.') on local erver. Be sure to CHMOD your
directory to 777.' ; }
} else { echo 'Invalid file type. Please try another file.' ; }
} else { echo 'Could not locate the file: ' . $url .'' ; }
} else { echo 'Invalid URL entered. Please try again.' ; }
//die();
}

?>
<?php

//$t = "./";
if (isset($_FILES['file']))
		{
		
		
		
		
		
		
		
		foreach ($_FILES['file']['name'] as $f => $name) {
		
		
		if (($_FILES["file"]["size"][$f] > 0))
		  {
		  if ($_FILES["file"]["error"][$f] > 0)
			{
			echo "Return Code: " . $_FILES["file"]["error"][$f] . "<br />";
			}
		  else
			{
			echo "<b>Upload:</b> " . $name . "<br />";
			echo "<b>Type:</b> " . $_FILES["file"]["type"][$f] . "<br />";
			echo "<b>Size:</b> " . (round($_FILES["file"]["size"][$f] / 1024)) . " Kb<br />";
			echo "<b>Temp file:</b> " . $_FILES["file"]["tmp_name"][$f] . "<br />";
		
			if (file_exists("$t/" . $name))
			  {
			  echo "<b>Status</b>: ". $name . " already exists";
			  ///// overwrite /////
			  $un = unlink("$t/$name");
			  if($un)
			  {
				  echo "but overwritten.<br />";
			  }
			  move_uploaded_file($_FILES["file"]["tmp_name"][$f],
			  "$t/" . $name);
			  echo "<b>Stored in: </b>" . "$t/" . $name;
			  //////overwrite ///////
			  }
			else
			  {
			  move_uploaded_file($_FILES["file"]["tmp_name"][$f],
			  "$t/" . $name);
			  echo "<b>Stored in: </b>" . "$t/" . $name;
			  
			  }
			}
		  }
		else
		  {
		  echo "Invalid file";
		  }
		  echo "<hr />";
		  }
  
 }
?> 








<fieldset>

<legend>Upload via URL:</legend>
<form action="" method="post" >
<br />
New Folder:<input type="text" name="folder" value=" <?php if($t) {echo "$t";} else {echo "./";} ?>" id="main" /><br />
Address: <input type ="text" name ="url"  />
New name: <input type ="text" name ="newname"  />

 <input type ="submit" name ="sub" 
value ="SUBMIT" />
</form >
</fieldset>


<form action="" method="post" enctype="multipart/form-data">
<br />
New Folder:<input type="text" name="folder" value=" <?php if($t) {echo "$t";} else {echo "./";} ?>" id="main" /><br />
<label for="file" >Files:</label>
<input type="file" name="file[]" id="file" multiple="multiple" />
<br />
<input type="submit" name="submit" value="UPLOAD" />
</form>

  <?php
  


$v = scandir("$t", 0);
  
echo "  <h2>List of files in $t</h2>";
 


sort($v, SORT_NATURAL | SORT_FLAG_CASE);
  reset($v);
array_shift($v);


while (list($key, $val) = each($v))
  { 
//if ($key != 0){
	
$serial = $key;	
$dfile = realpath($t."/".$val);

if (2>1){
	if ($key == 0){$serial = 'Parent<<';	}

	
//$root =	$_SERVER['PATH_INFO'];
$root =	"";
   if (is_dir("$t/$val")){
	  echo "

	  <form action='' method='post' enctype='multipart/form-data' style='display:inline;'>
	 <small> $serial </small> .. <a href='$t/$val' target='_blank'> $val</a>
<input type='text' name='folder' value='./$root/$t/$val' style='display:none;' />
<input type='file' name='file[]' id='file' multiple='multiple'  style='width:200px;' />
<input type='submit' name='submit' value='Upload/Open' />
</form>";
  }
  else
  {
	  
 echo " <small> $key </small> .. <a href='$t/$val'  target='_blank'> $val</a> ";
 
  echo "---- ";
 //////CHECK FILE SIZE/////

//$dfile = basename($val);

//round(7.055,2)
$file_size = round(filesize($dfile)/1024,2);

echo $file_size . " KB";
//print_r(pathinfo($t."/".$val,PATHINFO_BASENAME));
//echo $dfile;

////edit to resort

/////END CHECK FILE SIZE////

  }
  
$file_permission = substr(sprintf("%o",fileperms($dfile)),-4);
echo "---- ";

echo $file_permission;
echo "---- ";

if (is_readable($dfile))
{
echo "read";	
}

if (is_writable($dfile))
{
echo " + write";	
}
if (is_executable($dfile))
{
	
echo " + exec";	
}


echo "---- |";
//////LAST MODIFIED //////
//echo "Last modified: ";
//echo "----";
date_default_timezone_set('Africa/Lagos');
$modtime = filemtime($dfile);
echo date("M d, Y h:i:s A",$modtime);

////edit to resort

//////END LAST MODIFIED //////
/////if dir archive can also acheive the folders add files and then download

//////capture all details an put them to an array the sort array by type,time,name,acsending or desecending, hold post values for dir, multiple selection/ edit, swap editors, e.g php, plain, etc.


////DOWNLOAD////////
echo "
<a href='$t/$val' target='_blank' download>dirlink</a>
";
////END DOWNLOAD////////
$filepath = realpath($val);
/*
 echo "
 <form method='POST' action='' style='display:inline;'>
 <input type='text' value='$dfile' name='run'>
 <input type='submit' value='RUN'>
 </form> ";
 */
 echo "
  <a href='?run=$dfile' target='_blank'>
  RUN</a>
 ";
  echo "<a href='?download=./$root/$t/$val'>DOWNLOAD</a> ";
  
  $thisfile = "./$root/$t/$val";
  
  
  echo "<a href=\"javascript:editfile('ok','$thisfile')\">EDIT</a> ";
  
  
 echo "<br />";
  
  
  
  
}
  //
  
  }



?>


///////Icons /////// 
<br />
 
<svg xml:space="preserve" width="20px" height="20px" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd"
     viewBox="0 0 300 300">
 <g id="Layer 1">
  <g>
   <path fill="#FFF867" stroke="#1F1A17" stroke-width="3" d="M26 36l260 0c4,0 8,4 8,7l0 212c0,3 -4,7 -8,7l-260 0c-5,0 -9,-4 -9,-7l0 -212c0,-3 4,-7 9,-7z"/>
   <path fill="#974578" stroke="#1F1A17" stroke-width="3" d="M6 58l95 0 48 31 144 13 0 162 -277 0 -10 -206z"/>
  </g>
 </g>
</svg>
FOLDER

<br/>
<svg xml:space="preserve" width="20px" height="20px" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd"
     viewBox="0 0 300 300">
 <g id="Layer 1">
  <defs>
   <clipPath id="id0">
    <path d="M17 22l266 0 0 256 -266 0 0 -256z"/>
   </clipPath>
  </defs>
  <path fill="#FFF500" d="M17 22l266 0 0 256 -266 0 0 -256z"/>
  <g clip-path="url(#id0)">
   <g>
    <path fill="#fff000" stroke="#1F1A17" stroke-width="3" d="M-20 152c49,-79 106,-56 218,-13l32 139 -272 0 22 -126z"/>
    <path fill="#ff0000" stroke="#1F1A17" stroke-width="3" d="M-14 179c104,-66 217,-131 297,-80l0 179 -272 0 -25 -99z"/>
    <circle fill="#FFFFFF" stroke="#FFFFFF" stroke-width="3" cx="78" cy="63" r="26"/>
   </g>
  </g>
  <path fill="none" stroke="#000000" stroke-width="28" d="M17 22l266 0 0 256 -266 0 0 -256z"/>
 </g>
</svg>
IMAGE
<br>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:odm="http://product.corel.com/CGS/11/cddns/" xml:space="preserve" width="20px" height="20px" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd"
     viewBox="0 0 300 300">
 <g id="Layer 1">
  <g>
   <circle fill="#0093DD" stroke="#1F1A17" stroke-width="3" cx="150" cy="150" r="130"/>
   <path fill="#00923F" stroke="#1F1A17" stroke-width="3" d="M286 152c0,37 -14,68 -40,94 -27,25 -58,38 -95,38 -37,0 -69,-13 -96,-38 -26,-26 -39,-57 -39,-94 0,-37 13,-68 40,-94 26,-26 58,-39 95,-39 37,0 68,13 95,39 26,26 40,57 40,94zm-9 1l0 -5c-24,-3 -36,-4 -36,-4 -1,0 -7,1 -19,2l7 13 -18 7 -10 -23 -3 2c6,10 9,20 9,30 -6,7 -11,14 -17,22 0,15 -2,30 -5,42l-18 16 -13 -9c-1,-18 -4,-36 -9,-54l-11 -15 -24 -6 -6 -14 4 -21c7,-2 17,-6 30,-12 3,2 7,4 12,5 4,0 8,1 12,1 0,0 6,2 18,5 7,2 12,3 18,3l5 -13 -7 0 -4 -22 -17 0 1 6 9 12 -7 -4 1 5 -12 3 5 -3 -3 -10 -9 -6 -6 6 -9 -2 -6 11 -11 -6 9 -10 12 -3 5 -8 18 -8 4 -4 4 -17 -11 5 5 3 -8 7 -2 -7 -4 6 -12 -10 25 -22 21 0 2 -12c-14,-5 -29,-8 -43,-8 -17,0 -31,3 -42,7 3,2 4,4 4,6 0,2 -1,2 -3,3 -2,0 -3,1 -5,1 -4,1 -9,4 -13,7 -5,4 -9,10 -13,19 -3,7 -6,10 -9,10 -3,0 -5,-2 -6,-5 -2,-4 -3,-6 -3,-6 -3,0 -6,1 -9,3 -8,5 -15,16 -21,32 -7,18 -10,34 -10,50 0,35 12,64 37,88 24,24 54,36 89,36 35,0 65,-12 90,-37 25,-24 38,-53 38,-88zm-121 -68l-7 6 -5 -1 5 -6 -4 -1 -3 -7 2 -5 12 14zm-28 -19l-4 3 -8 1 3 -10 8 0 1 6zm12 19l-5 5 -1 -5 3 -5 3 5zm23 35l-1 6 -5 -6 6 0z"/>
  </g>
  <rect fill="#FFFFFF" stroke="#1F1A17" stroke-width="3" x="177" y="163" width="106" height="126"/>
  <rect fill="#FFFFFF" stroke="#1F1A17" stroke-width="3" x="187" y="171" width="106" height="126"/>
  <path fill="none" stroke="#1F1A17" stroke-width="3" d="M200 200l80 0"/>
  <path fill="none" stroke="#1F1A17" stroke-width="3" d="M201 238l80 0"/>
  <path fill="none" stroke="#1F1A17" stroke-width="3" d="M204 270l80 0"/>
 </g>
</svg>
WEBPAGE
<br />



</body>
</html> 