Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Questing about Write and Read

Status
Not open for further replies.

imryn

Programmer
Dec 2, 2002
75
US
Hello Folks,

Here's what I am thinking I would like to do. I would like to create an administrator web page that Writes to a file, then have my index page Read the content and display in in a small table. So my thought is am I work to hard here or is there a better way to do this ?

Thanks,
imryn
 
Hello Again,

I was thinking again... the information will be changing monthly on the index page, so would I be better off to write the information to a database, then call it from the database?

Thanks,
imryn
 
Why not just rewrite the page every month when you want it changed?

Lee
 
Lee,

That is how I am currently doing it, and the issue is I want to get away from being the web admin of this site. I am currently re-designing it, and be more user freindly and so that they do not need some one with programming experience to update the site every Month. There are severy pages that need updated on this page.

imryn
 
ryan

your suggestion is fine. there are other solutions too - google for javascript "edit in place" for a js solution.

for php read and write solution (this is very basic - designed to put you on the right track only:

Code:
<?
error_reporting(E_ALL);
session_start();
function displaycurrentcontent() {
	$contentfile = "content.txt";
	if (file_exists($contentfile)):
		$content = file_get_contents($contentfile);
	else:
		$content = "";
	endif;
	return $content;
}
function writecontent() {
	if (
		isset($_SESSION['uniqid']) && 
		isset($_POST['uniqid']) && 
		($_SESSION['uniqid'] === $_POST['uniqid'])
		):
		$contentfile = "content.txt";
		set_magic_quotes_runtime(0);
		if (!empty($_POST['content'])):
			if (get_magic_quotes_gpc()):
				$content=stripslashes($_POST['content']);
			else:
				$content = $_POST['content'];
			endif;
			$len = strlen($content);
			if (!is_writable($contentfile)) die ("File is not writeable.  Check permissions");
			$fh = fopen($contentfile, "wb");
			fwrite($fh, $content, $len);
			fclose ($fh);
		endif;
	endif;
}
if (isset($_POST['submit'])):
	writecontent();
endif;
$_SESSION['uniqid'] = uniqid("rw_");
?>

<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="uniqid" value="<?=$_SESSION['uniqid']?>" />
<textarea name="content" id="contenttextarea">
</textarea>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>

<hr/>

Current content:
<div id="contentdiv" style="border:1px solid blue; width:70%; margin:0 auto;">
<? echo displaycurrentcontent(); ?>
</div>
<input type="submit" name="edit" value="Edit" onclick="document.getElementById('contenttextarea').value = document.getElementById('contentdiv').innerHTML; return true;"/>
 
jpadie,

Thanks for the insight.

imryn
 
just a thought - but if you combine the method above with a wysisig in-web editor like FCKEditor, then your users would have quite a powerful method of updating their web site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top