DIR : /home/kozerus/public_html/mking/mking.php

/home/kozerus/public_html/mking

<?php

$dirnam="./anyt";
$outfil="./anyt.txt";
$dir="/Volumes/ka1tbr2/i";
$filematch="anyt_*.pdf";
$filematch='/^anyt_*\.(pdf|)$/';
$pathfile="/Volumes/ka1tbr2/i/anyt_*.pdf";


	echo "<body bgcolor=linen>\n";
	$hostname=system("hostname");
	echo "$hostname<br>";
//	if( $hostname == "ka1" ) { echo "hostname=$hostname<br>\n"; }
//	if( $hostname == "ka2" ) { echo "hostname=$hostname<br>\n"; }

	$fmt=""; 
	if( isset( $_REQUEST['fmt'])) { 
		$fmt=trim(htmlspecialchars($_REQUEST['fmt'])); 
		echo "BUGS_100 isset fmt=$fmt<br>\n";
		}

	$todo=""; 
	if( isset( $_REQUEST['todo'])) { 
		$todo=trim(htmlspecialchars($_REQUEST['todo'])); 
		echo "BUGS_100 isset todo=$todo<br>\n";
		}

	if( $todo == "" ) {
		echo "mking.php?todo=hostname # do everything<br>\n";
		echo "mking.php?todo=go # do everything<br>\n";
		echo "mking.php?todo=filework # check ../../i and copy renamed anyt_*.pdf files to anyt/<br>\n";
		echo "mking.php?todo=cr # create anyt.txt<br>\n";
		echo "mking.php?todo=cat # cat anyt.txt<br>\n";
		echo "mking.php?todo=ssh_anyt # ssh anyt.txt<br>\n";
		echo "mking.php?todo=ssh_pdfs # ssh anyt/anyt_*.pdf<br>\n";

		}

	if(( $todo == "go" ) || ( $todo == "filework" )) { filework(""); }
	if(( $todo == "go" ) || ( $todo == "cr" )) { cr_anyt(""); }
	if(( $todo == "go" ) || ( $todo == "cat" )) { cat_anyt(""); }
	if(( $todo == "go" ) || ( $todo == "ls" )) {
		$dirnam="anyt";
		$dirlist=ls($dirnam);
		echo "dirnam=$dirnam dirlist=$dirlist<br>\n";
		}
	if(( $todo == "go" ) || ( $todo == "ssh_anyt" )) { ssh_anyt(""); }
	if(( $todo == "go" ) || ( $todo == "ssh_pdfs" )) { ssh_pdfs(""); }



//	$files=findfiles_glob($pathfile);
//	echo "BUGS_100 pathfile=$pathfile files=$files<br>\n";


//	$files=findfiles($dir,$filematch);
//	echo "BUGS_100 dir=$dir $filematch=$filematch files=$files<br>\n";

//	$dirlist=ls($dirnam);
//	echo "dirnam=$dirnam dirlist=$dirlist<br>\n";

//	$syscmd="ssh konet@ka2 'ls -lat /Volumes/ka2tbr1/ht/mking/anyt'";
//	$syscmd="scp anyt.txt konet@ka2:/Volumes/ka2tbr1/ht/mking";
//	$output=sys($syscmd);

//	$phrase  = "You should eat fruits, vegetables, and fiber every day.";
//	$newphrase=string_replace($phrase);
//	echo "BUGS_20 phrase=$phrase<br>\nnewphrase=$newphrase<br>\n";

//	$filename="../../i/anyt_250214 File Name with spaces and Special Characters a| bc!@£de^&f g' .pdf";
//	$cleanname=clean($filename);
//	$cleanname=str_replace("_pdf",".pdf",$cleanname);
//	echo "filename=$filename<br>\ncleanname=$cleanname<br>\n";


function clean($string) {
	$string = str_replace(' ', '_', $string); // Replaces all spaces with hyphens.
	return preg_replace('/[^A-Za-z0-9\_\.\/]/', '', $string); // Removes special chars.
	}






function string_replace($phrase) {

// Provides: You should eat pizza, beer, and ice cream every day
//	$phrase  = "You should eat fruits, vegetables, and fiber every day.";
	$healthy = array("fruits", "vegetables", "fiber");
	$yummy   = array("pizza", "beer", "ice cream");

	$newphrase = str_replace($healthy, $yummy, $phrase);
	return($newphrase);
	}



function sys($syscmd) {
	$output="";
// +----------------+-----------------+----------------+----------------+
// |    Command     | Displays Output | Can Get Output | Gets Exit Code |
// +----------------+-----------------+----------------+----------------+
// | system()       | Yes (as text)   | Last line only | Yes            |
// | passthru()     | Yes (raw)       | No             | Yes            |
// | exec()         | No              | Yes (array)    | Yes            |
// | shell_exec()   | No              | Yes (string)   | No             |
// | backticks (``) | No              | Yes (string)   | No             |
// +----------------+-----------------+----------------+----------------+


	$output=passthru($syscmd);
	return($output);
	}

function findfiles_glob($pathfile) {
	$files=""; $j=0;
	
//	foreach (glob("*.txt") as $filename) {
	foreach (glob($pathfile) as $filename ) {
		$j=$j+1;
		echo "$j $filename size " . filesize($filename) . "\n";
		$files.=$filename."|".filesize($filename)."\n";
		}
	return($files);
	}


function findfiles_scandir($dir,$filematch) {
	$files="_files_";
	date_default_timezone_set('America/New_York'); //change to your timezone
//	$directory = 'Your Directory';
	$files = scandir($dir);
	foreach($files as $file) {
		if(!preg_match('~\.a$~', $file) && !is_dir($dir. $file)) {
			$time["$file"] = filemtime($upload_directory . $file);
			}
		}
	array_multisort($time);


	return($files);
	}




function findfiles_iterator($dir,$filematch) {
	$files="_files_"; $j=0; $k=0;
	echo "BUGS_100 dir=$dir filematch=$filematch<br>\n";

	$directoryIterator = new RecursiveDirectoryIterator($dir);
	$iteratorIterator = new RecursiveIteratorIterator($directoryIterator);
//	$fileList = new RegexIterator($iteratorIterator, '/^.*\.(txt|TXT)$/');
	$fileList = new RegexIterator($iteratorIterator, $filematch);
	foreach($fileList as $file) {
		$j=$j+1;
		echo "$j $file";
		$files.=$file."\n";
		}

	return($files);
	}

function ls($dirnam) {
	$dirlist="";
//	if ($handle = opendir('.')) {
	if ($handle = opendir($dirnam)) {
		while (false !== ($entry = readdir($handle))) {
			if ($entry != "." && $entry != "..") {
				echo "$entry\n";
				$dirlist=$dirlist."<br>\n".$entry;
				}
			}
		closedir($handle);
		}

	return($dirlist);
	}


function filework($args) {
	$source_dir = "../../i";
	if (!is_dir($source_dir)) {
		die("Error: Source directory does not exist.");
		}

	echo "BUGS_160 source_dir=$source_dir<br>\n";

	$destination_dir = '/Volumes/ka1tbr2/ht/mking/anyt';
	if (!is_dir($destination_dir)) {
		if (!mkdir($destination_dir, 0755, true)) {
			die("Error: Destination directory could not be created.");
	    		}
		}
	echo "BUGS_161 destination_dir=$destination_dir<br>\n";


	$files = scandir($source_dir);

	$file_list = array();
	$j=0; $k=0;
	foreach ($files as $file) {
		$j=$j+1;
//		echo "BUGS_162 FOREACH_FILE j=$j file=$file<br>\n";

		$full_path = $source_dir . '/' . $file;
    
// Check if the filename starts with "anyt_" and is a file
		if (fnmatch("anyt*", $file, FNM_PATHNAME | FNM_PERIOD)) {
			if (is_file($full_path)) {

				$tofile=clean($file);

				$dest_full_path = $destination_dir . '/' . $tofile;
				if (copy($full_path, $dest_full_path)) {
					$k=$k+1;
//					$file_list[] = $file;
					$file_list[] = $tofile;

//					echo "BUGS_163 COPY_FILE k=$k full_path=$full_path dest_full_path=$dest_full_path<br>\n";
					echo "BUGS_163 COPY_FILE k=$k full_path=$full_path dest_full_path=$dest_full_path<br>\n";
					}
				}
    			}
		}
	return($file_list);
	}

function cr_anyt($args) {
//	$syscmd="ssh konet@ka2 'ls -lat /Volumes/ka2tbr1/ht/mking/anyt'";
//	$syscmd="scp anyt.txt konet@ka2:/Volumes/ka2tbr1/ht/mking";
	$syscmd="ls anyt/anyt_*.pdf | sort -r > anyt.txt";
//	$output=sys($syscmd);
	$output=system($syscmd);
	echo "BUGS_210 cr_anyt syscmd=$syscmd<br>output=$output<br>\n";
	}

function cat_anyt($args) {
	$syscmd="cat anyt.txt | sed -e s:$:'<br>':";
//	$output=passthru($syscmd);
	$output=system($syscmd);
	echo "BUGS_211 cat_anyt syscmd=$syscmd<br>output=$output\n";
	}

function ssh_anyt($args) {
	$syscmd="ssh anyt.txt konet@ka2:/Volumes/ka2tbr1/ht/mking";
//	$output=passthru($syscmd);
	$output=system($syscmd);
	echo "BUGS_220 ssh_anyt syscmd=$syscmd<br>output=$output\n";
	}

function ssh_pdfs($args) {
	$syscmd="ssh anyt/anyt_*.pdf konet@ka2:/Volumes/ka2tbr1/ht/mking/anyt/";
//	$output=passthru($syscmd);
	$output=system($syscmd);
	echo "BUGS_221 ssh_pdfs syscmd=$syscmd<br>output=$output\n";
	}


function create_anyttext_() {
// Create the output file
	$j=0;
	$destination_file = $destination_dir . '/anyt.txt';
	echo "BUGS_15 destingation_file=$destination_file<br>\n";
	$handle = fopen($destination_file, 'w');
	foreach ($file_list as $file) {
		$j=$j+1;
		fwrite($handle, $file . "\n");
		echo "BUGS_14 j=$j file=$file<br>\n";
		}
	fclose($handle);
	}

function filecheck($filename) {
	if( $filename == "" ) { $filename="anyt.txt"; }
	$j=0; $k=0;
	if( is_file($filename)) {
		$fh = fopen($filename, "r");
		while (($line = fgets($fh)) !== false) {
			$j=$j+1;
			echo "$j line=$line<br>\n";
			}
		fclose($fh);
		}
	else {
		echo "$progid NOTFOUND filename=$filename<br>\n";
		}
	}

//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer