Sorry for being cryptic. It would refresh and say "not writable!" But I got that figured out. I found out the "is_writable" command actually checks if the file exists and I was creating the file after that check. So I just moved the line where I created the file above that check and now it is working.
However, it is only saving in the home directory no matter if I go into a directory or not. I would like it to save in whatever directory I am currently in. I am passing along the name of the directory and even echoing it out in the file editor window correctly. But when I hit save and echo out where it saved to, the variable somehow changes back to the home directory.
Here is my current code:
<?php
$filedir = $_GET["value"];
$cwd = getcwd();
if($filedir == "")
{
$filedir = ".";
$cwd = $cwd."/";
}else{
$cwd = $cwd."/".$filedir; // concat paths
echo $cwd;
}
if(is_readable($filedir)) //check the get "value" is readable
{
?>
</div>
<h1>Currently in <span class="red"><?php echo $cwd; ?></span></h1>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="center">
<textarea rows="30" cols="80" style="border: 1px solid #666666;" name="updatedfile">
</textarea><br /></div>
<div class="center">Name of file: <input type="text" name="filename" id="filename" /><br /><div id="hidden"></div>
<input type="submit" name="save" id="save" value="Save Changes" onclick="return checkIfEmpty(document.getElementById('filename').value)" />
<?php
if (isset($_POST['save']))
{ //if the "save" button was clicked
$file=$_POST['filename'];
$file = $cwd.$file;
echo "$cwd is: ".$cwd;
$file2save = fopen($file, "w+");
if (is_writable($file))
{
$data_to_save = $_POST["updatedfile"];
$data_to_save = eregi_replace("<END-TA-DO-NOT-EDIT>", "</textarea>", $data_to_save);
if (fwrite($file2save,$data_to_save))
{
//echo "<meta http-equiv='refresh' content='0;URL=MikesFileEditor.php'>";
echo "file saved!";
//Close file
fclose($file2save);
}else {
//If write fails show failure page
echo "file not saved!";
//Close file
fclose($file2save);
}
}else {
echo "not writable!";
}
}
}
?>
Thanks
Mike