Thanks brad, it worked at first, but now for some reason it isn't working anymore, I CHMOD'd the file directory to 777 before writing to the file, but for some reason it says permission denied.. This is the error messages I get:
Warning: fopen(index.php): failed to open stream: Permission denied in /home/adam/public_html/majyk/test/edit.php on line 33
Warning: fwrite(): supplied argument is not a valid stream resource in /home/adam/public_html/majyk/test/edit.php on line 36
Warning: fclose(): supplied argument is not a valid stream resource in /home/adam/public_html/majyk/test/edit.php on line 44
edit.php
<?php
error_reporting(2047); // debug
$test = new edit;
class edit{
function edit(){
if(isset($_POST['subfilename'])){
$this->form();
}
else if(isset($_POST['subeditfile'])){
$this->editfile();
}
}
function form(){
$filename = $_POST['filename'];
$file=fopen($filename, "r");
$read=fread($file, 900000);
echo "Editing: <b>" . $filename . "</b><br><br>"
. "<form id='form1' name='form1' method='post' action='edit.php'>"
. "Edit:<br /><textarea name='edit' id='edit'>" . $read . "</textarea>"
. "<input name='subeditfile' type='hidden' id='subeditfile' value='1' />"
. "<input name='filename' type='hidden' id='filename' value='" . $filename . "' />"
. "<input type='submit' name='Submit' value='Submit' /></form>";
fclose($file);
}
function editfile(){
$filename = $_POST['filename'];
$string_edit = $_POST['edit'];
chmod($filename, 777);
$open_read=fopen($filename, "r");
$file_read=fread($open_read, filesize($filename));
$open_edit=fopen($filename, "w");
if ($string_edit != $file_read && $file_read !=''){
fwrite($open_edit, $string_edit);
} else if ($file_read != $string_edit) {
echo "Success,<br><br>" . $string_edit . "<br><br>has been written to "
. $filename;
} else if ($file_read != $string_edit){
echo "Error,<br><br>" . $string_edit . "<br><br>Could not be written to "
. $filename;
}
fclose($open_edit);
}
};
?>
I don't get why it would work at first, but now it doesn't?