...

View Full Version : php coding assistance with templete.php



herbal_lavender
12-23-2005, 06:21 PM
I get this error:

Warning: feof(): supplied argument is not a valid stream resource in /home/herbals/public_html/community/membersonly/template.php on line 48

Warning: fgets(): supplied argument is not a valid stream resource in /home/herbals/public_html/community/membersonly/template.php on line 49

Here is my code:

<?php
/*
class: template
purpose: template engine
*/
class template extends membersonly{

/*
function: define_file
purpose: defines template file
*/
function define_file($file){
$this->template_file=$file;
$this->template_regioncount=-1;
}

/*
function: add_region
purpose: adds template dynamic region
*/
function add_region($region,$value){
$this->template_regioncount++;
$this->template_regions[$this->template_regioncount]=$region;
$this->template_regionvalues[$this->template_regioncount]=$value;
}

/*
function: debug
purpose: set debugging to true
*/
function debug(){
$this->template_debug="true";
}

/*
function: make_template
purpose: make and display template
*/
function make_template() {
$fp = @fopen($this->membersonly_path.$this->template_dir.$this->template_file,"r");
$regioncount=count($this->template_regions);
for ($i=0; $i<$regioncount; $i++){
if ($this->template_regions[$i]=="headers"){
$page=$this->template_regionvalues[$i];
}
}
$page.="<!--This community runs on Herbal Sacred Ground Web Hosting ".$this->membersonly_version."\nhttp://herbalsacredground.com-->\n";
while (!feof($fp)){
$line = fgets($fp);
$line = stripslashes($line);
$line = preg_replace("/href=\"..\//","href=\"".$this->membersonly_webpath,$line);
$line = preg_replace("/src=\"..\//","src=\"".$this->membersonly_webpath,$line);
for ($i=0; $i<$regioncount; $i++){
$line = preg_replace("/{".$this->template_regions[$i]."}/",$this->template_regionvalues[$i],$line);
}
$page.=$line;
}
$tempfile=$this->membersonly_path.$this->template_tempdir.rand(111111111,999999999).".php";
$temp = @fopen($tempfile,"w+");
fwrite($temp, $page);
fclose($temp);
include ($tempfile);
if ($this->template_debug=="false"){
unlink($tempfile);
}
}

}
?>

Velox Letum
12-23-2005, 07:06 PM
It looks like the file doesn't exist to me, or you don't have permissions to modify it.

herbal_lavender
12-23-2005, 07:39 PM
What do you mean?

GJay
12-23-2005, 07:47 PM
Putting @ in front of functions before you know they work is really silly.
Try fopen(...) or die("COuldn't open file on line xxx");
instead, and it might be helpful

missing-score
12-23-2005, 08:02 PM
Also, please wrap your code in [PHP] tags as described here (http://www.icdsoftware.com/tags).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum