hey i searched the forums but couldnt find an answer to my problem:
im including a file that hold my nav for an editor that i made. if i try to save the file with the button in the included file it wont work, altho the filename seems to be parsed right, and other buttons sending the filename in a hidden field work right, but if i try to save it with the button in the main file, it works fine.
any idea on what im doing wrong?? thanks for the help!
index.php
<?php
include("header.php");
if($save) {
$contents = stripslashes($contents);
$contents = utf8_encode($contents);
$handle = fopen("/home/bla/public_html/text/" . $filename, "w");
fwrite($handle, $contents)
or die("Can't write file");
fclose($handle);
echo("<table>");
echo(" <tr>");
echo(" <td align='center' colspan='2'>");
echo(" File saved!");
echo(" </td>");
echo(" </tr>");
echo("</table>");
} elseif ($filename) {
$handle = fopen("/home/bla/public_html/text/" . $filename, "r");
$contents = "";
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$contents .= $data;
} while(true);
fclose($handle);
$contents = urldecode($contents);
if($newentry) {
if(strpos($filename, 'erman') == true) {
$todaydate = date("d.m.Y");
$firstpart = '&textUpdate=letzte Aktualisierung';
} else {
$firstpart = '&textUpdate=last updated';
$todaydate = date("m/d/Y");
}
if(strpos($contents, 'news=') == false) {
$rest = strstr($contents, '<p>');
$contents = "&archive1=\n".'<p>'.$todaydate."</p>\n".$rest;
} else {
$rest = strstr($contents, '<p>');
$contents = $firstpart.' '.$todaydate."\n&news=\n".'<p>'.$todaydate."</p>\n".$rest;
}
}
echo("<div align='center'>Editing file: $filename ");
echo(" <form name='form1' action='$PHP_SELF' METHOD='POST'>");
echo(" <textarea name='contents' rows=28 cols=100 id='contents'>$contents</textarea><br>");
echo(" <input type='hidden' name='filename' value='$filename'>");
echo(" <input type='submit' name='save' value='Save'>");
echo(" </form>");
echo("</div>");
?>
ignore the newentry part, its not really important what i did with it...
now my header.php
<?php
echo("<div align='center'>");
echo("<table>");
echo(" <tr>");
echo(" <td>");
echo(" English News:<br>");
echo(" German News:<br>");
echo(" English diary:<br>");
echo(" German diary:<br>");
echo(" </td>");
echo(" <td>");
echo(" <form action='$PHP_SELF' method='POST'>");
echo(" <input type='radio' name='filename' value='news.txt' CHECKED><br>");
echo(" <input type='radio' name='filename' value='germannews.txt'><br>");
echo(" <input type='radio' name='filename' value='whatsupenglish.txt'><br>");
echo(" <input type='radio' name='filename' value='whatsupgerman.txt'><br>");
echo(" </td>");
echo(" <td>");
echo(" <input type='submit' value='choose'>");
echo(" </form>");
echo(" </td>");
echo(" <td width='50'>");
echo(" </td>");
echo(" <td>");
echo(" <form action='$PHP_SELF' method='POST'>");
echo(" <input type='hidden' name='filename' value='$filename'>");
echo(" <input type='submit' name='save' value='Save'>");
echo(" <input type='submit' name='newentry' value='create new entry'>");
echo(" </form>");
echo(" </td>");
echo(" <td width='50'>");
echo(" </td>");
echo(" <td align='right'>");
echo(" <form action='$PHP_SELF' method='POST'>");
echo(" <input type='submit' name='crashsession' value='logout'>");
echo(" </form>");
echo(" </td>");
echo(" </tr>");
echo("</table>");
echo("</div>");
echo("<hr noshade='noshade' width=100% size='2' align='center'>");
?>