I have a PHP page that is tasked with displaying the content of a file and allowing the user to modify said content.
When user clicks on the submit button, the file is overwritten with the new content and the page refreshes. A message displays to the user the new content that has been written.
My problem is that the code goes through, but the file is not actually modified. The submit happens, the modification message is dispayed, but the file contents do not change.
Any ideas ?
I've got nothing to hide, and I'd very much like to keep that away from prying eyes.
When user clicks on the submit button, the file is overwritten with the new content and the page refreshes. A message displays to the user the new content that has been written.
My problem is that the code goes through, but the file is not actually modified. The submit happens, the modification message is dispayed, but the file contents do not change.
Code:
<html>
<head>
<title>Editer fichier</title>
<link rel="stylesheet" type="text/css" href="./style.css" title="fichier1">
</head>
<body>
<?php
include("start.php");
function customError($errno, $errstr){
}
?>
<tr><td colspan="2" class="page_section">
<h1>Liste des fichier html</h1>
<table class="html_section"><tr><td class="file_section">
<?php
//this section gets the available files and makes a bullet list
$authorized=array("html");
$rep=opendir("./html");
$fichiers[0]="";
while($entree = readdir($rep)){
$extention=substr($entree,strlen($entree)-4);
if(in_array($extention,$authorized)){
echo "<li><a href='edit.php?&file=$entree'>$entree</a></li>";
}
}
$notify=false;
?>
<br/>
</td><td class="html_section">
<?php
//this section checks for whether or not there is a modification to write and which file to display
$param_file="";
set_error_handler("customError");
$param_file=$_GET["file"];
$letexte=isset($_REQUEST["modification"])?$_REQUEST["modification"]:".";
//write update if it exists
if(strlen($letexte)>2){
$modfic = fopen($filename,"w");
fputs($modfic,$letexte);
fclose($modfic);
$notify=true;
}
//read file content
if(strlen($param_file)>0){
echo "<h2>$param_file</h2>";
$filename="html/".$param_file;
$input_file=file($filename);
echo "<form><input type='hidden' name='file' value='$param_file'/><textarea cols='65' rows='5' name='modification'>";
foreach($input_file as $k){
echo $k;
}
echo "</textarea><input type='submit' name='$param_file' value='Envoyer' /></form>";
//if there has been a change, notify user
if($notify){
echo "<div class='message'> Le texte <br> $letexte <br> a été écrit dans le fichier $fichier </div>";
$notify=false;
}
}
?>
</td></tr></table>
<br/>
</td></tr>
<tr><td colspan="2" class="large_section"><br/><br/></td></tr>
</table>
</body>
</html>
Any ideas ?
I've got nothing to hide, and I'd very much like to keep that away from prying eyes.