Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic File Class Help (PHP) (Read 1996 times)
Acid_Blast
New Member
*
Offline


I love YaBB 1G - SP1.2!

Posts: 14
Joined: Mar 22nd, 2005
File Class Help (PHP)
Mar 28th, 2005 at 10:14pm
Print Post  
hi,

I need some help with this class I can't figure out why its not working

Code
Select All
<?php
/*
Template Class
File: template.php
*/

/* Begin Template Class */

class template {
var $temp;
var $size;
var $mode;
var $directory;

function template() {
	$this->directory = "/home/user/public_html/templates";
}

function topen($filename, $blocksize, $read) {
$this->temp = $filename;
$this->size = $blocksize;
$this->mode = $read;
if($fp = fopen("$directory/$filename", "$read")) {
$data = '';
while(!feof($fp)) {
$data .= fread($fp, "$blocksize");
}
}else{
	print "Error: Could not open template from $directory/$filename";
}
print $data;
fclose($fp);
}
}
?>
 



Code
Select All
<?php
/*
Display Template(s)
File: test.php
*/

/* Include Template Class */
include('./template.php');

/* Call Template Class */
$template = new template;

/* Display Template */
$template->topen("main.txt",'1572864','r');

?>
 



I'll explain what its suppost to do incase I am no where close to how its suppost to be.  Its suppost to open the file in this case main.txt located in the templates directory and read the code in blocks of 1572864 Bytes  (or 1.5MB). And output the resulting HTML.

[EDIT]
It currently doesn't seem to follow the $directory variable it just trys to read /main.txt if I hard code the path in there /home/user/templates it works.  Can somone help me fix this?

Also how would I preform more then one eregi_replace() on the same bit of information and have it print the results only 1 time?

when i do
Code
Select All
echo eregi_replace("{news}","$news", "$data");
echo eregi_replace("{who_online}","$whois","$data");
 



it prints the page out twice.

Thanks for your help,
-AB
  
Back to top
 
IP Logged
 
Jedi
Full Member
***
Offline



Posts: 104
Location: Sarasota
Joined: Mar 28th, 2002
Gender: Male
Re: File Class Help (PHP)
Reply #1 - Mar 31st, 2005 at 4:09am
Print Post  
It doesn't follow the $directory, because you must continue to use $this->

For example:
Code
Select All
<?php
/*
Template Class
File: template.php
*/

/* Begin Template Class */

class template
{
   var $temp,
	   $size,
	   $mode,
	   $directory;

   function template()
   {
	$this->directory = '/home/user/public_html/templates';
   }

  function topen($filename, $blocksize, $read)
  {
     $this->temp = $filename;
     $this->size = $blocksize;
     $this->mode = $read;

     if($fp = fopen($this->$directory.'/'.$this->temp, $this->mode))
     {
	    $data = '';
	    while(!feof($fp))
	    {
		   $data .= fread($fp, "$blocksize");
	    }
	 }
	 else
	{
	   echo 'Error: Could not open template from '.$this->directory.'/'.$this->temp';
	}

	echo $data;
	fclose($fp);
   }
}
?>
 

  
Back to top
 
IP Logged
 
Acid_Blast
New Member
*
Offline


I love YaBB 1G - SP1.2!

Posts: 14
Joined: Mar 22nd, 2005
Re: File Class Help (PHP)
Reply #2 - Mar 31st, 2005 at 5:49pm
Print Post  
Thanks Jedi, but now i get:

Code
Select All
Parse error: parse error, unexpected '\'', expecting ',' or ';' in /home/user/public_html/template.php on line 38
 



line 38 is
Code
Select All
echo 'Error: Could not open template from '.$this->directory.'/'.$this->temp';
 



if i comment that line out it sort of works but it tries to open /template.txt instead of /home/user/public_html/templates/template.php

any clue why?

Also I just have one more besides the above problem.
I'm using eregi_replace(); to replace tags like {news} {who_online} {menu} and such but when I go
Code
Select All
echo eregi_replace("{news}","$news","$data");
echo eregi_replace("{who_online}","$who_online","$data");
echo eregi_replace("{menu}","$menu","$data");
 



it displays the page 3 times and replaces each object in a seperate version of the page.

How do i get it to replace all of the tags and then output the result only 1 time?
  
Back to top
 
IP Logged
 
Administrator
Forum Administrator
*****
Offline


Yummm

Posts: 7
Location: Modders Rile
Joined: Oct 7th, 2014
Gender: Male
Re: File Class Help (PHP)
Reply #3 - Mar 31st, 2005 at 6:27pm
Print Post  
Removing the last ' from line 38 will fix the error.

Oh and don't echo the output of eregi_replace directly if you want to call eregi_replace a couple of times. In that case, write the output back into the input variable and do a single echo at the end. The code would like this:

Code
Select All
$data = eregi_replace("{news}",$news,$data);
$data = eregi_replace("{who_online}",$who_online,$data);
$data = eregi_replace("{menu}",$menu,$data);
echo $data; 

  

The Administrator.
Back to top
WWW  
IP Logged
 
Acid_Blast
New Member
*
Offline


I love YaBB 1G - SP1.2!

Posts: 14
Joined: Mar 22nd, 2005
Re: File Class Help (PHP)
Reply #4 - Mar 31st, 2005 at 7:26pm
Print Post  
Thanks Michael, now I just have one problem the $this->directory is being set fine but its not working in the fopen(); part.

I get
Quote:
Warning: fopen(/main.txt): failed to open stream: No such file or directory in /home/user/public_html/template.php on line 27
Error: Could not open template from /home/user/public_html/templates/main.txt
Warning: fclose(): supplied argument is not a valid stream resource in /home/user/public_html/template.php on line 41
  
Back to top
 
IP Logged
 
Administrator
Forum Administrator
*****
Offline


Yummm

Posts: 7
Location: Modders Rile
Joined: Oct 7th, 2014
Gender: Male
Re: File Class Help (PHP)
Reply #5 - Mar 31st, 2005 at 10:28pm
Print Post  
Replacing $this->$directory with $this->directory should do the job Wink
  

The Administrator.
Back to top
WWW  
IP Logged
 
Acid_Blast
New Member
*
Offline


I love YaBB 1G - SP1.2!

Posts: 14
Joined: Mar 22nd, 2005
Re: File Class Help (PHP)
Reply #6 - Mar 31st, 2005 at 10:37pm
Print Post  
Thanks Michael.  I can't belive I didnt notice that Sad

now if I could just get that login check code working from the other thread...  Tongue
  
Back to top
 
IP Logged
 
Jedi
Full Member
***
Offline



Posts: 104
Location: Sarasota
Joined: Mar 28th, 2002
Gender: Male
Re: File Class Help (PHP)
Reply #7 - Apr 1st, 2005 at 2:08am
Print Post  
Whoops sorry about that, maybe I should wait until I'm more awake to answer PHP questions  Tongue
  
Back to top
 
IP Logged
 
Administrator
Forum Administrator
*****
Offline


Yummm

Posts: 7
Location: Modders Rile
Joined: Oct 7th, 2014
Gender: Male
Re: File Class Help (PHP)
Reply #8 - Apr 1st, 2005 at 11:05am
Print Post  
Quote:
Whoops sorry about that, maybe I should wait until I'm more awake to answer PHP questions  Tongue
Hehe I'm too familiar with that problem too Roll Eyes.
  

The Administrator.
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint