PHP
<?php
if ($changefile) {
$savedEdit = stripslashes($_POST['filetest']);
$filetochange = "../dashboard/list.ini";
$filetochangeOpen = fopen($filetochange,"w") or die ("Error editing.");
fputs($filetochangeOpen,$savedEdit);
fclose($filetochangeOpen) or die ("Error Closing File!");
}
?>
HTML form
<form method=post action="mmtst.php">
<textarea rows="40" cols="60" name="filetest">
<?
// Implode CSS
$filetochange = "../dashboard/list.ini";
print (implode("",file($filetochange)));
?>
</textarea><br/><br/>
<input type="submit" value="Save Changes" name="changefile">
</form>
Here I have a page that displays an INI file in a text box. What should happen is that when I click the submit button, the original file is opened, and fputs writes to the original with anything that is displayed in the txtbox. (the original file is set to permissions 777). However, nothing happens when the submit button is clicked, I have no idea what I am doing wrong, any suggestions would be awesome.
if($changefile), try dumping that, because by the looks of things: it might be an undefined variable, in which case the file is never opened, let alone written to. Also checkout file_put_contents, replace theputwithgetto get it's reading counterpart. It doesn't require those extra lines of opening and closing a file