Reading CSS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Reading CSS

Post by SidewinderX »

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?

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";
	}


}

?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

put the if statement above the part where you read the document
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

Excellent! Thanks :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

your welcome
Post Reply