Click to See Complete Forum and Search --> : Quote Script Help


comptech520
10-18-2007, 01:20 PM
I haev a question. I have this script. There are 3 files. index.php, list.php and quotes.txt. The quotes.txt file is supposed to be CHMOD to 777. I tried that and it didn't write to that file on my server. I have had a common problem with text files not writing on my server. It is a VPS.

Do you have any idea's or suggestions to make this script work?

Here are the contents of the first two files and you can make up the quotes.txt.

index.php
<html>
<head>
<title>Rampant Quotes</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>

<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td align="center">

<?
$yourfile="quotes.txt";

$updates = $HTTP_POST_VARS["updates"];

if ($updates) {
$thequotes = implode("|", $HTTP_POST_VARS[quotes]);
$allquotes = explode("|", $thequotes);

foreach($allquotes as $key => $value){

if($value !="" && $value !=" ")
{
$newquotes .= $value."|";
}
}
$fp = fopen($yourfile, "w") or die("Can't open file");
fwrite($fp, stripslashes(str_replace("\r", "", str_replace("\n", "", nl2br($newquotes)))));
fclose($fp);
}


$aquote = $HTTP_POST_VARS["aquote"];

if ($aquote) {
$fp = fopen($yourfile, "a") or die("Can't open file");
fwrite($fp, stripslashes(str_replace("\r", "", str_replace("\n", "", nl2br($aquote))))."|");
fclose($fp);
}
$n = 0;
$fp = fopen($yourfile, "r") or die("Can't open file");
while (!feof($fp)) {
$thequotes = fgets($fp);
}
fclose($fp);

function br2nl($str) {
$str = preg_replace("/(\r\n|\n|\r)/", "", $str);
return preg_replace("=<br */?>=i", "\n", $str);
}



?>
<br><center><b>CURRENT QUOTES</b></center>
<table border="0" cellpadding="5" cellspacing="0" style="width:500px;border:1px black solid;">
<form name="updateit" action="index.php" method="post">
<?
$allquotes = explode("|", $thequotes);

foreach($allquotes as $key => $value){
if($value)
{
echo "<tr><td colspan=2><textarea name=quotes[] class=quotebox>".br2nl($value)."</textarea></td></tr>";
}
}
?>
</td></tr></table><BR>
<center><input type="submit" name="updates" value="Update Quotes"></center>
</form>
<BR><BR>
<center><b>ADD QUOTE</b></center>
<table>
<tr><td align="center">
<form name="postit" action="index.php" method="post">
<textarea name="aquote" class="addquote" rows="3"></textarea>
<br><br><input type="submit" value="Add Quote">
</form>
</td></tr></table>
</body>
</html>

list.php
<?
$yourfile="quotes.txt";

$fp = fopen($yourfile, "r") or die("Can't open file");
while (!feof($fp)) {
$thequotes = fgets($fp);
}
fclose($fp);
$thequotes = rtrim($thequotes, "|");
$thequotes = ltrim($thequotes, "|");
$allquotes = explode("|", $thequotes);
$randomentry = array_rand($allquotes, 1);
echo $allquotes[$randomentry];
//Unquote this to see all of the items in the quote array.
//print_r ($allquotes);
?>

NightShift58
10-18-2007, 07:54 PM
It just didn't write or was there an associated error message?

comptech520
10-19-2007, 08:08 AM
there was no error, it just doesen't write