jbard Posted January 5, 2010 Share Posted January 5, 2010 Hi I am trying to add a comment section to my website and i am having a few problems, the script i am adding is called FFcomment i'm using it because it doesnt require a database and it suited my needs, i seem to have everything sorted apart from when someone tries to post a comment and i get these three errors: Warning: file(AbstractTXT.txt) [function.file]: failed to open stream: No such file or directory in /home/jbardcon/domains/jbard.co.nz/public_html/tutorial/FFcomments/FFGuestbook.php on line 44 Warning: array_slice() expects parameter 1 to be array, boolean given in /home/jbardcon/domains/jbard.co.nz/public_html/tutorial/FFcomments/FFGuestbook.php on line 52 Warning: Invalid argument supplied for foreach() in /home/jbardcon/domains/jbard.co.nz/public_html/tutorial/FFcomments/FFGuestbook.php on line 110 Now i have checked them permisions on the text file are set to 755 and i also check it does exist . here the php code: <? include "FFGB_inc/FFGBfuncs.php"; //################################# //# User Editable Variables Below # //################################# $Gbookfile = "AbstractTXT.txt"; //DO NOT EDIT UNLESS YOU HAVE RENAMED THE GUESTBOOK FILE $PageTitle = "Leave a comment for this tutorial"; // Will appear at the top of the window $headertext = "Leave a comment on JbardTutorials"; // Will appear at the top of the page $timezone = "Pacific/Auckland"; //Supported Time Zones: http://uk2.php.net/manual/en/timezones.php $debug = 0; // 1=On 0=Off, Enable if you are having problems with messages not being entered into the guestbook properly $enablepost = 1; // 1=Yes, 0=No, Self Explanatory - Change to 0 to disable posting. $style = "bl"; // bl=Blue, rd=Red, gr=Green, leave blank to default to blue. $sortorder = "DESC"; // ASC=Newest First, DESC=Oldest, Firsthow the script should order the comments $maxwd = "61"; // Maximum number of letter per line, NOTE: will not break HTML tags, will try to insert a <BR> in a space if not possible will break a work, but will not break any HTML tag. // Default Value = 61 $display = 20; // How many comments to display per page //######################################## //# End Of User Editable Variables Below # //# Do Not Edit Below This Line # //######################################## SelectStyle($style); ?> <title><? echo $PageTitle; ?></title> <h2><? echo $headertext; ?></h2> <? WriteComment($name,$email,$comment, $Gbookfile); $pg = (isset($_REQUEST['pg']) && ctype_digit($_REQUEST['pg'])) ? $_REQUEST['pg'] : 1; $start = $display * $pg - $display; /* paginating from a flat file */ $data = file("$Gbookfile"); $total = count($data); if($sortorder == 'ASC') // Check how to order comments { //$recs = array_reverse($news); // Reverse the order of comments if set to ASC $news = array_slice(array_reverse($data), $start, $display); }else{ $news = array_slice($data, $start, $display); } if (isset($_SERVER['QUERY_STRING']) && trim($_SERVER['QUERY_STRING']) != '') { if(stristr($_SERVER['QUERY_STRING'], 'pg=')) $query_str = '?'.preg_replace('/pg=\d+/', 'pg=', $_SERVER['QUERY_STRING']); else $query_str = '?'.$_SERVER['QUERY_STRING'].'&pg='; } else $query_str = '?pg='; $pages = ($total <= $display) ? 1 : ceil($total / $display); $first = '<a href="'.$_SERVER['PHP_SELF'].$query_str.'1">« </a>'; $prev = '<a href="'.$_SERVER['PHP_SELF'].$query_str.($pg - 1).'"> ‹</a>'; $next = '<a href="'.$_SERVER['PHP_SELF'].$query_str.($pg + 1).'"> ›</a>'; $last = '<a href="'.$_SERVER['PHP_SELF'].$query_str.$pages.'"> »</a>'; if($debug == 1) // Check if Debug is turned on. { echo "<font color=\"red\"><br><br> A Succesful debug should show 4 peices of information below this line: Name, Email, Comment and Datestamp.<br>If you don't have 4 peices of information below then there is misspelling in a variable somewhere check to ensure the text contained in the square brackets above ".'$_POST['."' '".']'." matches each of the form fields at the bottom.</font>"; echo "<br><br><b>Beginning of Debug echo</b><br>"; echo "\n".strip_tags($name)."|".strip_tags($email)."|$timestamp|$datestamp|".strip_tags($comment); echo "<b>End of Debug Echo</b><br><font color=red>to disable this message above change $debug to 0 by editing Gbook.php</font><br>------------------------<br><br>"; }else{} $recs = array(); /* Redundant as of V1.2 //////////////////////////////////////////// //open file to display comments $handle = fopen("$Gbookfile", "r"); while(true) { $line = fgets($handle); if($line == null)break; $cnt = array_push($recs, $line); // Add one to end of array } fclose($handle); //////////////////////////////////////////// //for ($i=0, $num = count($recs); $i < $num; $i++) { */ foreach($news as $value) { $parts = explode("|", $value); // Find instances of | in each line and split the string up where each one is found. /* Check Comment For Smilies */ $text = array("",":cool:","",":drool:",":grin:",":happy:",":mad:",":sad:",":sleepy:",":smile:",":suprised:",":tongue:"); $images = array("<img title=\Confused\ src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/confused.gif\">","<img title=\"Cool\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/cool.gif\">","<img title=\"Cry\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/cry.gif\"> ","<img title=\"Drool\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/drool.gif\"> ","<img title=\"Grin\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/grin.gif\"> ","<img title=\"Happy\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/happy.gif\"> ","<img title=\"Mad\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/mad.gif\"> ","<img title=\"Sad\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/sad.gif\"> ","<img title=\"Sleepy\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/sleepy.gif\"> ","<img title=\"Smile\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/smile.gif\"> ","<img title=\"Suprised\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/suprised.gif\"> ","<img title=\"Tongue\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/tongue.gif\"> ",); $parts[4] = str_replace($text,$images,bbcode_format($parts[4])); // check for empty lines if(strlen($parts['0']) !== 1) { echo "<Table id=\"style-b\">"; echo "<tr><th scope=\"col\"><b>Posted By:</b> $parts[0] <b>at</b> $parts[2], $parts[3]</th><tr>"; echo "<tr><td><b>Comments:</b> ". breakLongWords($parts['4'],"$maxwd","<br />")."</td></tr>"; echo "</Table>"; }}//} echo '<table id="style-a"><tr><th align="center">'; echo ($pg > 1) ? "$first : $prev :" : '« : ‹ :'; $begin = $pg - 4; while($begin < 1) $begin++; $end = $pg + 4; while($end > $pages) $end--; for($i=$begin; $i<=$end; $i++) echo ($i == $pg) ? ' ['.$i.'] ' : ' <a href="'. $_SERVER['PHP_SELF'].$query_str.$i.'">'.$i.'</a> '; echo ($pg < $pages) ? ": $next : $last" : ': › : »'; echo '</th></TR></table>'; ?> <table id="style-b"> <tr><th align="center"><form name="comform" method="post" onSubmit="return checkbae() && checkrequired(this) && stripHTML(this.requiredcoms)"> Your Name:<br> <input type="text" name="requiredname" value="<? if($captchastatus !== "TRUE"){ echo $name;} ?>"><br> Your E-Mail:<br><font color="red" size="-2" value="">*Required, but not shown on the page</font><br> <input type="text" value="<? if($captchastatus !== "TRUE"){echo $email;} ?>" name="checkemail"><br> Your Comments:<br> <? echo "$smlinks $forlinks"; ?> <textarea id="comsta" name="requiredcoms" rows=6 ><? if($captchastatus !== "TRUE"){echo $comment;} ?></textarea> <br> <br>Security Code: <br> <input id="security_code" name="security_code" type="text" /><br><img src="http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/CaptchaSecurityImages.php" /><br> <? if($enablepost == 1){ echo "<input type=\"submit\" value=\"Post!!\">";}else{ echo "<input type=\"submit\" value=\"Posting Disabled\" disabled>";}?> </th></tr></table> and just incase you need it here is the code from the include file: <? // Smilie Buttons $smlinks = "<img title=\"Confused\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/confused.gif\" name=\"conf\" onclick=\"ChgText('con')\">"; $smlinks .= "<img title=\"Cool\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/cool.gif\" name=\"cool\" onclick=\"ChgText('col')\">"; $smlinks .= "<img title=\"Cry\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/cry.gif\" name=\"cry\" onclick=\"ChgText('cry')\">"; $smlinks .= "<img title=\"Drool\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/drool.gif\" name=\"drool\" onclick=\"ChgText('drl')\">"; $smlinks .= "<img title=\"Grin\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/grin.gif\" name=\"grin\" onclick=\"ChgText('grn')\">"; $smlinks .= "<img title=\"Happy\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/happy.gif\" name=\"hap\" onclick=\"ChgText('hap')\"><br>"; $smlinks .= "<img title=\"Mad\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/mad.gif\" name=\"mad\" onclick=\"ChgText('mad')\">"; $smlinks .= "<img title=\"Sad\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/sad.gif\" name=\"sad\" onclick=\"ChgText('sad')\">"; $smlinks .= "<img title=\"Sleepy\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/sleepy.gif\" name=\"slp\" onclick=\"ChgText('slp')\">"; $smlinks .= "<img title=\"Smile\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/smile.gif\" name=\"sml\" onclick=\"ChgText('sml')\">"; $smlinks .= "<img title=\"Suprised\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/suprised.gif\" name=\"sup\" onclick=\"ChgText('sup')\">"; $smlinks .= "<img title=\"Tongue\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/FFGBSmilies/tongue.gif\" name=\"ton\" onclick=\"ChgText('ton')\"><br>"; ////////////////////////////////////////////////////////////////////// // Formatting Buttons $forlinks = "<img title=\"Bold\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/BBC/bold.gif\" name=\"bold\" onclick=\"BBCode_Replace('bold')\">"; $forlinks .= "<img title=\"Italic\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/BBC/italic.gif\" name=\"ital\" onclick=\"BBCode_Replace('ital')\">"; $forlinks .= "<img title=\"Underline\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/BBC/underline.gif\" name=\"unde\" onclick=\"BBCode_Replace('unde')\">"; $forlinks .= "<img title=\"Url\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/BBC/url.gif\" name=\"url\" onclick=\"BBCode_Replace('url')\">"; $forlinks .= "<img title=\"Image\" src=\"http://www.tutorial.jbard.co.nz/FFcomments/FFGB_inc/BBC/img.gif\" name=\"img\" onclick=\"BBCode_Replace('img')\"><br>"; ////////////////////////////////////////////////////////////////////// // BBCode // based on http://www.phpit.net/article/create-bbcode-php/ // modified by www.vision.to // please keep credits, thank you // document your changes. function bbcode_format ($str) { $str = htmlentities($str); $simple_search = array( //added line break '/\[br\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[mail\=(.*?)\](.*?)\[\/mail\]/is', '/\[mail\](.*?)\[\/mail\]/is', '/\[font\=(.*?)\](.*?)\[\/font\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', //added textarea for code presentation '/\[codearea\](.*?)\[\/codearea\]/is', //added pre class for code presentation '/\[code\](.*?)\[\/code\]/is', //added paragraph '/\[p\](.*?)\[\/p\]/is', ); $simple_replace = array( //added line break '<br />', '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', // added nofollow to prevent spam '<a href="$1" rel="nofollow" title="$2 - $1">$2</a>', '<a href="$1" rel="nofollow" title="$1">$1</a>', '<div style="text-align: $1;">$2</div>', //added alt attribute for validation '<img src="$1" alt="" />', '<a href="mailto:$1">$2</a>', '<a href="mailto:$1">$1</a>', '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', //added textarea for code presentation '<textarea class="code_container" rows="30" cols="70">$1</textarea>', //added pre class for code presentation '<pre class="code">$1</pre>', //added paragraph '<p>$1</p>', ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); // Do <blockquote> BBCode $str = bbcode_quote ($str); return $str; } function bbcode_quote ($str) { //added div and class for quotes $open = '<blockquote><div class="quote">'; $close = '</div></blockquote>'; // How often is the open tag? preg_match_all ('/\[quote\]/i', $str, $matches); $opentags = count($matches['0']); // How often is the close tag? preg_match_all ('/\[\/quote\]/i', $str, $matches); $closetags = count($matches['0']); // Check how many tags have been unclosed // And add the unclosing tag at the end of the message $unclosed = $opentags - $closetags; for ($i = 0; $i < $unclosed; $i++) { $str .= '</div></blockquote>'; } // Do replacement $str = str_replace ('[' . 'quote]', $open, $str); $str = str_replace ('[/' . 'quote]', $close, $str); return $str; } /* used in Vision.To CMS function VISION_TO_PAGE_CONTENT_PROCESSOR ($content) { $content=bbcode_format ($content); return $content; } */ /*Usage in CodeCharge Studio : before show event , the content_html is label property as HTML $content=bbcode_format ($cms_pages->content_html->GetValue()); $cms_pages->content_html->SetValue($content); */ /////////////////////////////////////////////////////// ?> <!-- Insert smilie short code into text area when user clicks on specific image --> <script type="text/javascript" language="javascript"><!-- function ChgText(smilietxt) { var MyElement = document.getElementById("comsta"); var Txtarea = document.comform.requiredcoms.value; if(smilietxt == 'con') { var smile = ""; } else if(smilietxt == 'col') { var smile = ":cool:"; } else if(smilietxt == 'cry') { var smile = ""; } else if(smilietxt == 'drl') { var smile = ":drool:"; } else if(smilietxt == 'grn') { var smile = ":grin:"; } else if(smilietxt == 'hap') { var smile = ":happy:"; } else if(smilietxt == 'mad') { var smile = ":mad:"; } else if(smilietxt == 'sad') { var smile = ":sad:"; } else if(smilietxt == 'slp') { var smile = ":sleepy:"; } else if(smilietxt == 'sml') { var smile = ":smile:"; } else if(smilietxt == 'sup') { var smile = ":suprised:"; } else if(smilietxt == 'ton') { var smile = ":tongue:"; } MyElement.value = Txtarea += smile; return true; } //--></script> <!-- Insert BBC short code into text area when user clicks on specific button --> <script type="text/javascript" language="javascript"><!-- function BBCode_Replace(bbcode1) { var MyElement = document.getElementById("comsta"); var Txtarea = document.comform.requiredcoms.value; if(bbcode1 == 'bold') { var bbcode = "[b][/b]"; } else if(bbcode1 == 'ital') { var bbcode = "[i][/i]"; } else if(bbcode1 == 'unde') { var bbcode = "[u][/u]"; } else if(bbcode1 == 'url') { var bbcode = "[url][/url]"; } else if(bbcode1 == 'img') { var bbcode = "[img][/img]"; } MyElement.value = Txtarea += bbcode; return true; } //--></script> <!-- ////////////////////////////////////////////////////// // Check for all required elements filled in --> <script> /* Check required form elements script- By JavaScript Kit (http://javascriptkit.com) Over 200+ free scripts here! */ function checkrequired(which){ var pass=true if (document.images){ for (i=0;i<which.length;i++){ var tempobj=which.elements[i] if (tempobj.name.substring(0,=="required"){ if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){ pass=false break } } } } if (!pass){ alert("One or more of the required elements are not completed. Please complete them, then submit again!") return false } else return true } </script> <!-- ////////////////////////////////////////// // Check valid email address --> <script language="JavaScript1.2"> //Advanced Email Check credit- //By JavaScript Kit (http://www.javascriptkit.com) //Over 200+ free scripts here! var testresults function checkemail(){ var str=document.comform.checkemail.value var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i if (filter.test(str)) testresults=true else{ alert("Please input a valid email address!") testresults=false } return (testresults) } </script> <script> function checkbae(){ if (document.layers||document.getElementById||document.all) return checkemail() else return true } </script> <? ////////////////////////////////// function SelectStyle($style){ // Style Selecter if ($style == "bl") { echo "<style type=\"text/css\"> #style-b { font-family:\"Lucida Sans Unicode\", \"Lucida Grande\", Sans-Serif; font-size:12px; width:480px; text-align:left; border-collapse:collapse;border:1px solid #69c;margin:20px; } #style-a { font-size:12px; width:480px; text-align:left; } #style-b th { font-weight:normal; font-size:14px;color:#039; padding:15px 10px 10px; background:#ffffff; } #style-b tbody { background:#e8edff; } #style-b td { color:#669; border-top:1px dashed #fff; padding:10px; } #style-b tbody tr:hover td { color:#339;background:#d0dafd; } </style>"; } elseif($style == "rd") { echo "<style type=\"text/css\"> #style-b { font-family:\"Lucida Sans Unicode\", \"Lucida Grande\", Sans-Serif; font-size:12px; width:480px; text-align:left; border-collapse:collapse;border:1px solid #69c;margin:20px; } #style-a { font-size:12px; width:480px; text-align:left; } #style-b th { font-weight:normal; font-size:14px;color:#039; padding:15px 10px 10px; background:#ffffff; } #style-b tbody { background:#FF9966; } #style-b td { color:#669; border-top:1px dashed #fff; padding:10px; } #style-b tbody tr:hover td { color:#339;background:#FF6600; } </style>"; } /*INSERT CUSTOM STYLES UNDER HERE*/ /*INSERT CUSTOM STYLES ABOVE HERE*/ elseif($style == "gr") { echo "<style type=\"text/css\"> #style-b { font-family:\"Lucida Sans Unicode\", \"Lucida Grande\", Sans-Serif; font-size:12px; width:480px; text-align:left; border-collapse:collapse;border:1px solid #69c;margin:20px; } #style-a { font-size:12px; width:480px; text-align:left; } #style-b th { font-weight:normal; font-size:14px;color:#039; padding:15px 10px 10px; background:#ffffff; } #style-b tbody { background:#CCFF99; } #style-b td { color:#669; border-top:1px dashed #fff; padding:10px; } #style-b tbody tr:hover td { color:#339;background:#66FF66; } </style>"; } else { echo "<style type=\"text/css\"> #style-b { font-family:\"Lucida Sans Unicode\", \"Lucida Grande\", Sans-Serif; font-size:12px; width:480px; text-align:left; border-collapse:collapse;border:1px solid #69c;margin:20px; } #style-a { font-size:12px; width:480px; text-align:left; } #style-b th { font-weight:normal; font-size:14px;color:#039; padding:15px 10px 10px; background:#ffffff; } #style-b tbody { background:#e8edff; } #style-b td { color:#669; border-top:1px dashed #fff; padding:10px; } #style-b tbody tr:hover td { color:#339;background:#d0dafd; } </style>"; }} ////////////////////////////////////////// // WordWrap function breakLongWords($str, $maxLength, $char){ $wordEndChars = array(" ", "\n", "\r", "\f", "\v", "\0"); $count = 0; $newStr = ""; $openTag = false; for($i=0; $i<strlen($str); $i++){ $newStr .= $str{$i}; if($str{$i} == "<"){ $openTag = true; continue; } if(($openTag) && ($str{$i} == ">")){ $openTag = false; continue; } if(!$openTag){ if(!in_array($str{$i}, $wordEndChars)){//If not word ending char $count++; if($count==$maxLength){//if current word max length is reached $newStr .= $char;//insert word break char $count = 0; } }else{//Else char is word ending, reset word char count $count = 0; } } }//End for return $newStr; } /////////////////////////////////////////////////// ?> <!-- Remove HTML from Comments Box --> <script type="text/javascript"> // Strip HTML Tags (form) script- By JavaScriptKit.com (http://www.javascriptkit.com) // For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/ // This notice must stay intact for use function stripHTML(){ var re= /<\S[^><]*>/g for (i=0; i<arguments.length; i++) arguments[i].value=arguments[i].value.replace(re, "") } </script> <!-- Start of Pagination Class --> <? /** |||||||||||||||||||||||||||||||||||||||||| |||| @author Tanax |||| @copyright 2008 |||||||||||||||||||||||||||||||||||||||||| **/ class pagination { // The total value. private $totalPages; private $totalResults; private $totalPerPage; // The current value. private $currentPage; private $currentSpan; private $firstResult; public function setMax($max) { if(is_numeric($max)) { $this->totalPerPage = $max; } } public function setPage($page) { if(is_numeric($page)) { $this->currentPage = mysql_real_escape_string($page); $this->firstResult = (($this->currentPage * $this->totalPerPage) - $this->totalPerPage); return $this->firstResult; } } public function getPages($results) { $this->totalResults = count($results); $totalPages = $this->totalResults / $this->totalPerPage; $this->totalPages = ceil($totalPages); $x = 1; $array = array(); while($x <= $this->totalPages) { $array[] = $x; $x++; } return $array; } public function checkLink($pagenr) { if($pagenr <= $this->totalPages && $pagenr >= 1) { return true; } return false; } public function getCurrentPage() { $array = array(); $array[] = $this->currentPage; $array[] = $this->totalPages; return $array; } } ?> <!-- End of Pagination Class --> <? function WriteComment($name, $email, $comment, $Gbookfile) { date_default_timezone_set($timezone); $name = $_POST['requiredname']; //DO NOT EDIT $email = $_POST['checkemail']; //DO NOT EDIT $comment = $_POST['requiredcoms']; //DO NOT EDIT $timestamp = date("H:i"); //DO NOT EDIT $datestamp = date("j-M-Y"); //DO NOT EDIT if(isset($name))// Checks if the form had been submitted { // check if Captcha is correct if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) { $fh = fopen($Gbookfile, "a"); // replace Carriage Returns with <BR /> for tidiness in flat file then convert to BBCode. $comment = nl2br($comment); $comment = preg_replace("/(\r\n)+|(\n|\r)+/", "", $comment); $comment = str_replace("<br />","[br]", $comment); $string = "\n".strip_tags($name)."|".strip_tags($email)."|$timestamp|$datestamp|$comment"; fwrite($fh, $string); $captchastatus = "TRUE"; unset($_SESSION['security_code']); } else { Echo "<font color=red><br>Anti-Spam Code Mistmatch, Please check and try again.</font>"; }} } ?> Hope you can help me with this i would really appreciate it. thanks Quote Link to comment https://forums.phpfreaks.com/topic/187242-writing-to-text-file-problem/ Share on other sites More sharing options...
salathe Posted January 5, 2010 Share Posted January 5, 2010 Your permissions look to be too restrictive, only the file owner can write to it and the chances are that user is not the same as the user that PHP runs as. Either change the ownership of the file, or use looser permissions (e.g. 0777). Quote Link to comment https://forums.phpfreaks.com/topic/187242-writing-to-text-file-problem/#findComment-988837 Share on other sites More sharing options...
teamatomic Posted January 5, 2010 Share Posted January 5, 2010 It has nothing to do with the file permissions. Its telling you it cant find the file. Try: $Gbookfile = "/home/jbardcon/domains/jbard.co.nz/public_html/tutorial/FFcomments/AbstractTXT.txt"; 1. make sure the file name is correct 2. make sure the file in in the FFcomments folder HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/187242-writing-to-text-file-problem/#findComment-988956 Share on other sites More sharing options...
jbard Posted January 5, 2010 Author Share Posted January 5, 2010 thanks you so much that solved my problem - im not sure why i would need to write the whole path to the file instead of just the name seen as they were in the same directory but what the heck it works so im happy Quote Link to comment https://forums.phpfreaks.com/topic/187242-writing-to-text-file-problem/#findComment-989257 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.