Gå til innhold

Problemer med å skjule tekst i en fil


Anbefalte innlegg

Jeg har børstet støv av en kode som lister opp alle mapper og filene i disse og muliggjør redigering av disse filene. Det er jeg er på jakt etter å gjøre er å gjøre slik at kun mappenavnene vises og når en trykker på disse (eller holder musepekeren over navnet) vil filene i mappen vises. Jeg har sittet i hele kveld uten å finne ut hva jeg gjør feil. er det noen ser hva som må endres?

 

 

 

<?php
/*
* This script performs a recursive search in folders of your choic and list the content. All files are 
* links and by clicking a filename you may edit the file in a file editor. 
*/

$filename =$_GET['filename']; //fetch the filename
$newdata = $_POST['newd']; //fetch txt in the txtarea
$folder_name ="."; //name of the folder containing the files

//This saves the edited text into the file
function save_to_file () { 
global $filename, $newdata, $folder_name;

if (!$newdata != '') die ("Textfield is empty");
if (!file_exists($filename)) die ("File ". $filename ." is not found");
$fw = file_get_contents($filename) or die('Could not open file ' . $filename . '!');;
$fb = file_put_contents($filename, $newdata) or die('Could not write to file ' . $filename . '!');;
//$fw = fopen($filename, 'w+') or die('Could not open file ' . $filename . '!');
//$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write to file');
fclose($fw);
echo "Informasjonen er lagret i filen. Trykk <a href='$_SERVER[php_self]?action=display&&filename=". $filename ."'>her</a> for å vise inholdet i filen.";
}

//This displays the content of the files in a txtarea in which you may edit your file.
function display_content () {
global $filename;
recursive_tree ();

$fh = fopen($filename, "r"); 
	if (!$fh) { error_message ("Could not open file."); }
$data = file_get_contents($filename); 
	if (!$data) { error_message ("Could not read file."); }
fclose($fh);
echo "</div><div><br>Her vises filen <b>$filename </b><br><form action='$_SERVER[php_self]?action=save&&filename=". $filename . "' method='post'>";
echo "<textarea name='newd' cols='100%' rows='30'> $data </textarea><br><input type='submit' value='Save file'></form></div>";
}

//This displays the default content.
function default_page () {
global $filename, $folder_name;
recursive_tree ();
echo "</div><h3>Choose file</h3><form action='$_SERVER[php_self]?action=save' method='post'>";
echo "<textarea name='newd' cols='100%' rows='30'> </textarea><br><input type='submit' value='Change'></form>";
}

//This function display the folder structure recursivly
function recursive_tree () {
echo ("<div class='vanlig'><div style='width:300px;float:left;height:700px'>");
// This function performs a recursive dive into the file structure 
function getDirectory($path = '.', $ignore = '') {
	$dirTree = array ();
	$dirTreeTemp = array ();
	$ignore[] = '.';
	$ignore[] = '..';
	$dh = @opendir($path);

	while (false !== ($file = readdir($dh))) {
		if (!in_array($file, $ignore)) {
			if (!is_dir("$path/$file")) {
				$dirTree["$path"][] = $file;
			} 
			else {
				$dirTreeTemp = getDirectory("$path/$file", $ignore);
				if (is_array($dirTreeTemp)) $dirTree = array_merge($dirTree, $dirTreeTemp);
			}
		}
	}
closedir($dh);
ksort ($dirTree);
return $dirTree;
}

//Here you decide which folders you want to exclude in the search
$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', 'includes', 'images', 'test', 'downloads', 'ex', 'pentax'); 
$dirTree = getDirectory('../', $ignore); // Here you set the root of the filetree you would like to display

//This loop displays the filestructure and displays the result. All filenames are links and by clicking their name you may edit the file. 
foreach ($dirTree as $value=>$mappenavn) { 
	$value = str_replace ('//', '/', $value);

	echo "<SPAN onMouseover=\"definitionID.style.display=''\" onMouseOut=\"definitionID.style.display='none'\"><br>" . $value . "<br></SPAN>";
	foreach ($mappenavn as $filnavn) { 
		echo "<div ID=\"definitionID\" STYLE=\"display:none\"><a href='$_SERVER[php_self]?action=display&&filename=" . $value . "/" . $filnavn . "'>" . $filnavn . "</a><br></div>";
		echo "<div><a href='$_SERVER[php_self]?action=display&&filename=" . $value . "/" . $filnavn . "'>" . $filnavn . "</a><br></div>";
	} 
}
}

function error_message ($error) {
echo ("</div><div>" . $error . "</div>");
exit;
}

//This Case Select 
switch ($_GET['action']) {
case "display";
	display_content();
break;
case "save";
	save_to_file();
break;
default;
	default_page();
break;
}
?> 

 

 

Endret av ilpostino
Lenke til kommentar
Videoannonse
Annonse

<?php
/*
* This script performs a recursive search in folders of your choic and list the content. All files are 
* links and by clicking a filename you may edit the file in a file editor. 
*/

$filename = ! empty( $_GET['filename'] ) ? $_GET['filename'] : ''; //fetch the filename
$newdata = ! empty( $_POST['newd'] ) ? $_POST['newd'] : ''; //fetch txt in the txtarea
$folder_name = "."; //name of the folder containing the files

//This saves the edited text into the file
function save_to_file () { 
       global $filename, $newdata, $folder_name;

       if ($newdata == '') die ("Textfield is empty");
       if (!file_exists($filename)) die ("File ". $filename ." is not found");
       $fw = file_get_contents($filename) or die('Could not open file ' . $filename . '!');;
       $fb = file_put_contents($filename, $newdata) or die('Could not write to file ' . $filename . '!');;
       //$fw = fopen($filename, 'w+') or die('Could not open file ' . $filename . '!');
       //$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write to file');
       fclose($fw);
       echo "Informasjonen er lagret i filen. Trykk <a href='?action=display&filename=". $filename ."'>her</a> for å vise inholdet i filen." . PHP_EOL;
}

//This displays the content of the files in a txtarea in which you may edit your file.
function display_content () {
       global $filename;
       recursive_tree ();

       $fh = fopen($filename, "r"); 
               if (!$fh) { error_message ("Could not open file."); }
       $data = file_get_contents($filename); 
               if (!$data) { error_message ("Could not read file."); }
       fclose($fh);
       echo "</div><div><br>Her vises filen <b>$filename </b><br><form action='?action=save&filename=". $filename . "' method='post'>" . PHP_EOL;
       echo "<textarea name='newd' cols='100%' rows='30'> $data </textarea><br><input type='submit' value='Save file'></form></div>" . PHP_EOL;
}

//This displays the default content.
function default_page () {
       global $filename, $folder_name;
       recursive_tree ();
       echo "</div><h3>Choose file</h3><form action='?action=save' method='post'>";
       echo "<textarea name='newd' cols='100%' rows='30'> </textarea><br><input type='submit' value='Change'></form>";
}

//This function display the folder structure recursivly
function recursive_tree () {
       echo "<script type='text/javascript'>
function toggle( div ){
var div1 = document.getElementById( div )
if (div1.style.display == 'none') {
	div1.style.display = 'block'
} else {
	div1.style.display = 'none'
}
}
</script><div class='vanlig'><div style='width:300px;float:left;height:700px'>" . PHP_EOL;
       // This function performs a recursive dive into the file structure 
       function getDirectory($path = '.', $ignore = array() ) 
       {
               $dirTree = array ();
               $dirTreeTemp = array ();
               $ignore[] = '.';
               $ignore[] = '..';
               $dh = @opendir($path);

			if( $dh !== FALSE )
			{
               	while (false !== ($file = readdir($dh))) 
               	{
					if (!in_array($file, $ignore)) {
						if (!is_dir("$path/$file")) {
							$dirTree[$path][] = $file;
						} 
						else 
						{
							$dirTreeTemp = getDirectory("$path/$file", $ignore);
							if (is_array($dirTreeTemp)) 
								$dirTree = array_merge($dirTree, $dirTreeTemp);
						}
                       }
				}

				closedir($dh);
				ksort ($dirTree);
				return $dirTree;
			}
       }

       //Here you decide which folders you want to exclude in the search
       $ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', 'includes', 'images', 'test', 'downloads', 'ex', 'pentax'); 
       $dirTree = getDirectory('./', $ignore); // Here you set the root of the filetree you would like to display

       //This loop displays the filestructure and displays the result. All filenames are links and by clicking their name you may edit the file. 
       $i = 1;
       /*echo "<pre>";
       print_r( $dirTree );*/
       foreach ($dirTree as $value=>$mappenavn) 
       { 
               $value = str_replace ('//', '/', $value);

               echo "<span onClick=\"toggle('definitionID_{$i}'); return false;\">" . $value . "<br></span>" . PHP_EOL;
               echo "<div id='definitionID_{$i}' style='display:none'>" . PHP_EOL;
               foreach ($mappenavn as $filnavn) { 
                       echo "\t<a href='?action=display&filename=" . $value . "/" . $filnavn . "'>" . $filnavn . "</a><br>" . PHP_EOL;
               }
               echo "</div><br />" . PHP_EOL;
               $i++;
       }
}

function error_message ($error) {
       echo ("</div><div>" . $error . "</div>");
       exit;
}

//This Case Select 
switch ($_GET['action']) {
       case "display";
               display_content();
       break;
       case "save";
               save_to_file();
       break;
       default;
               default_page();
       break;
}

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...