Reading CSS
Posted: Sat May 05, 2007 2:00 pm
I've built a very basic CMS, and I want to give the administrator the ability to customize the CSS for the template through the back end. I've created a basic script that opens the file and displays it in a textbox, the user can edit the content and submit the form which then rewrites the file with the new content. However, the textbox doesn't show the updated changes unless the user refreshes the page. Which leads me to my questions.
Is my method the best way to accomplish this? If not, please elaborate. If so, how can I refresh the page?
Is my method the best way to accomplish this? If not, please elaborate. If so, how can I refresh the page?
Code: Select all
<?php
$filename = "../style/style.css";
$fh = fopen($filename, 'r') or die("Can't open file");
$fc = fread($fh, filesize($filename));
fclose($fh);
echo "<form method='post' action='admin.php?option=mod_styleconfig' >
<textarea rows='20' cols='90' name='css'>".$fc."</textarea><br />
<input type='submit' />
</form>";
if(isset($_POST['css'])){
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file $filename";
exit;
}
if (fwrite($handle, $_POST['css']) === FALSE) {
echo "$filename is not writable";
exit;
}
fclose($handle);
} else {
echo "$filename is not writable";
}
}
?>