Okay, that little bit of code seemed to do the trick. It will now create the file, write the predefined code to the file, close the file; however, it will not read the file no mater how I try. I'm getting the warning:
Warning: filesize(): Stat failed for Resource id #5 (errno=2 - No such file or directory) in /homepages/19/d126260960/htdocs/websites/bluecollardigital.com/fms/htmledit/editfile.php on line 46
Warning: fread(): Length parameter must be greater than 0. in /homepages/19/d126260960/htdocs/websites/bluecollardigital.com/fms/htmledit/editfile.php on line 46
Could Not READ The File (Instance Two)
I've modified my script some, in an attempt to make it function somehow...I'm about to start pulling out my hair with this one.
Here is the new code:
<?
session_start();
ini_set('display_errors', 'On');
ini_set('display_startup_errors', 'On');
error_reporting(E_ALL);
//Send the user to the login page, if they aren't logged in
if(!$_SESSION['username']) {
echo "<center><font size='5' color='red'><b>PLEASE LOG IN</b></font></center>";
include('../.././includes/login_form.html');
exit();
}
//Grab the Session vars
foreach($_SESSION as $key => $value) {
$key = $value;
}
//Get Included Files Included :)
$include_dir = $_SERVER['DOCUMENT_ROOT'] . "/fms/includes/";
$include_config = $include_dir . "config.php";
$include_sql = $include_dir . "sql_connect.php";
require($include_config);
require($include_sql);
//Define some variable stuff
$directory = "http://www.bluecollardigital.com/fms/users/" . $username . "/";
$file_dir = $_SERVER['DOCUMENT_ROOT'] . "/fms/users/" . $username;
$file_name = $file_dir . "/index.html";
//if the file doesn't exist, create it
if(file_exists($file_name) === FALSE) {
echo "I know that " . $file_name . " doesn't exist<br>";
touch($file_name) or die("Could Not Create The File");
chmod($file_name,0666);
$fh = fopen($file_name, 'w+') or die("Could Not Write To The File");
$text = "<html>\r\n <head>\r\n <title>". $username . "'s Website</title>\r\n </head>\r\n <body>\r\n </body>\r\n </html>";
fwrite($fh,$text) or die("Could Not Write To The File");
$file = fread($fh,filesize($fh)) or die("Could Not READ The File (Instance One)");
fclose($fh);
}
else{
//read the contents of the file to be displayed in the textarea
$fp = fopen($file_name, 'r') or die("Could Not Open File");
$file = fread($fp,filesize($fp)) or die("Could Not READ The File (Instance Two)");
fclose($fp);
}
echo "<div align='center'>";
require("http://www.bluecollardigital.com/header.php");
echo "</div>";
?>
<div align="center">
<form name="htmledit" method="post" action="../../savefile.php">
<input type="hidden" name="file_name" value="index.html">
<textarea rows="10" cols="60" wrap="off"><? echo $file; ?></textarea><br>
<input type="submit" name="submit" value="Save File">
</form>
</div>
</body>
</html>
Thanks again for everyone's help.