The Goal:
To take the selected skin from that drop down and have the html contents open into a text area which can will show me the current contents, allow me to edit it via the admin, and save the changes thus overwriting what was already there.
The Problem:
I THINK* I have the fread and fopen and fwrite commands right. However, because one of the directories in the file path is going to be dynamic (becuase there are three skins) I get a warning saying no such file or directory.
Another Problem:
I tried a test file that had a fixed path..not dynamic..just to test the functionality of my html form text area and it pulled the contents!!!! YAY!!! Success right? Well, I deleted the html code and typed the word testing. and hit update......upon refresh..the file was empty. When I looked into the server at that exact file and opened it..the old contents were still there....like its not overwriting. Now the contents arent opening anymore.
The CODE for FORM:----------------------Please note I had to include some things to create the administration panel to wrap around the file contents-------This File is named stm.php------------------------------------------------------------------------------------------------------------------------
<?php
include("../../includes/ini.inc.php");
include("../../includes/global.inc.php");
require_once("../../classes/db.inc.php");
$db = new db();
include_once("../../includes/functions.inc.php");
$config = fetchDbConfig("config");
include_once("../../language/".$config['defaultLang']."/lang.inc.php");
$enableSSl = 1;
include_once("../../includes/sslSwitch.inc.php");
include("../includes/auth.inc.php");
include("../includes/functions.inc.php");
if(permission("settings","read")==FALSE){
header("Location: ".$GLOBALS['rootRel']."admin/401.php");
exit;
}
if(isset($_POST['config'])){
$config = fetchDbConfig("config");
$msg = writeDbConf($_POST['config'],"config", $config, "config");
}
$config = fetchDbConfig("config");
$jsScript = jsGeoLocation("siteCountry", "siteCounty", "-- ".$lang['admin']['na']." --");
include("../includes/header.inc.php");
?>
<p class="pageTitle"><?php echo $lang['admin']['settings']['store_settings']; ?></p>
<?php
if(isset($msg)){
echo stripslashes($msg);
} else {
?>
<p class="copyText"><?php echo $lang['admin']['settings']['edit_below']; ?></p>
<?php } ?>
<table>
<tr>
<td width="30%" class="tdText"><strong><?php echo $lang['admin']['settings']['store_skin'];?></strong></td>
<td align="left">
<?php
$path = $GLOBALS['rootDir']."/skins";
if ($dir = opendir($path)) {
?>
<select class="textbox" name="config[skinDir]">
<?php
while (false !== ($file = readdir($dir))) {
if(!eregi($file,array(".",".."))){
?>
<option value="<?php echo $file; ?>" <?php if($file==$config['skinDir']) { echo "selected='selected'"; } ?>><?php echo $file; ?></option>
<?php
}
}
?>
</select>
<?php } ?> </td>
</tr><tr><td>
<form action="getfile.php" method="POST">
<table border="0" cellpadding="7" cellspacing="0" align="center" class="generaltable">
<tr>
<td align="center" class="fieldname" colspan="2">Custom Template</td>
</tr>
<tr>
<td align="center" colspan="2">
Paste your custom template's HTML code below, including all HTML tags<br>
and any <a href="includes/sitecodes.htm" target="_blank" onClick="PopUp=window.open('includes/sitecodes.htm',
'NewWin', 'resizable=yes,scrollbars=yes,width=400,height=400,left=0,top=0,screenX=0,screenY=0');
PopUp.focus(); return false;">site include codes</a> as needed. Use absolute references for all of your<br>
images and links, instead of relative ones. (ie. <a href="page.php">Page</a><br>
would be written as <a href="http://www.yoursite.com/page.php">Page</a>)</td>
</tr>
<td>
<tr>
<td align="center" colspan="2">
<textarea rows="20" name="store_template" cols="55">
<?php
$fn = "skins/".$config['skinDir']."/styleTemplates/global/index.tpl";
print htmlspecialchars(implode("",file($fn)));
?>
</textarea></td>
</tr>
<tr>
<tr>
<td width="30%" class="tdText"> </td>
<td align="left">
<input name="submit" type="submit" class="submit" id="submit" value="Update Settings" /></td>
</tr>
</tr>
</table>
</form>
</td></tr></table>
<?php include("../includes/footer.inc.php"); ?>
-------------------------------------------------------------------------------------------------------
And now for the getfile.php that controls the form
-------------------------------------------------------------------------------------------------------
<?php
$fn = "skins/".$config['skinDir']."/styleTemplates/global/index.tpl";
$store_template = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$store_template);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=stm.php\" />\n";
?>
------------------------------------------------------------------------------------------------
These files are both in the same folder. So how do I specify the path correctly..and get this thing to open, read out the file contents inside the html text area, allow me to make changes to that html data, and to when I hit save..have it overwrite the file so that when the page refreshes..I see my changes and the file in the server has been changed as well.
I have spent 14 hours doing this!!! Its my first php script