TinyPortal

Development => Support => Topic started by: Z.O.D on May 14, 2010, 12:16:15 AM

Title: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 12:16:15 AM
Can I put an include file somewhere so my php block can grab data from it?
Title: Re: Can I put an include file somewhere
Post by: JPDeni on May 14, 2010, 02:11:54 AM
Yes. You should probably put it in your Sources directory, which will allow you to use something like


include "file.inc";


The Sources directory is the current directory when a block is evaluated. If you don't want it to be in that directory, you either will need to use the whole path (not URL!) to the file or use a path that is relative to the Sources directory.
Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 02:20:04 AM
Awesome, can I use an absolute path?

This is what I put before the doc type right

<?php
include('/home/content/mysite/html/locationtofile/blahblah.php')
?>

Oh, okay, you mean put my file in the sources directory and use a relative path, gotchya :D..Thanks for that! Ill give it a try.
Title: Re: Can I put an include file somewhere
Post by: JPDeni on May 14, 2010, 02:31:05 AM
Don't use the


<?php


and


?>


The code in a php block is executed by way of an "eval" function, so you don't use those like you would in a separate file.
Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 02:35:18 AM
So I don't use any php tags in all of my code? Im getting an error unexpected <

Im getting this error now

Parse error: syntax error, unexpected '<' in /home/content/mysite/html/forum/Sources/Load.php(1967) : eval()'d code(48) : eval()'d code on line 3
Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 02:52:10 AM
Is it stricly php only? cant I have html in there as well?
Title: Re: Can I put an include file somewhere
Post by: JPDeni on May 14, 2010, 02:55:10 AM
You can have html, but don't put the tags at the beginning or the end. You can have them in the middle as you would for a regular file.

If you can't figure it out, post your full code (use code tags -- the # button on the reply screen) and I'll see if I can help you with it.
Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 03:00:36 AM
that'd be awesome if you could help me please :D..THanks so much for your help!


include "_ott_header.php";

<center><br />
<font color="#FFFF00" size="4">Bock<br /><br />
~~~~~~~~~~~<br /><br />
<font color="#66CC00" size="4"><b><i><center> BlockCR($dbPre, $dbPre2, $conn, $conn2);<br />( BlockCRDTG($dbPre, $dbPre2, $conn, $conn2);  to go!)</center></i></b></font><br />
~~~~~~~~~~~<br /><br />
Next 5</font><br /><br />
<font color="#cccccc" size="3"> BlockNF($dbPre, $dbPre2, $conn, $conn2); </font>
</center>

Title: Re: Can I put an include file somewhere
Post by: JPDeni on May 14, 2010, 03:04:46 AM


include "_ott_header.php";
?>

<center><br />
   <font color="#FFFF00" size="4">Bock<br /><br />
   ~~~~~~~~~~~<br /><br />
   <font color="#66CC00" size="4"><b><i><center> BlockCR($dbPre, $dbPre2, $conn, $conn2);<br />( BlockCRDTG($dbPre, $dbPre2, $conn, $conn2);  to go!)</center></i></b></font><br />
   ~~~~~~~~~~~<br /><br />
   Next 5</font><br /><br />
   <font color="#cccccc" size="3"> BlockNF($dbPre, $dbPre2, $conn, $conn2); </font>
</center>
<?php



I'm not sure what the BlockCR thing is. Is that a javascript? Or, in the original code are there more times that <?php and ?> are used that you took out? If there are, this won't work. Post the whole original code.
Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 03:14:36 AM
Yeah sorry, I thought you said to take that stuff out..I gave the modified code from my block, heres the original


include "_ott_header.php";
<center><br />
<font color="#FFFF00" size="4">Block<br /><br />
~~~~~~~~~~~<br /><br />
<font color="#66CC00" size="4"><b><i><center><?php BlockCR($dbPre$dbPre2$conn$conn2); ?><br />(<?php BlockCRDTG($dbPre$dbPre2$conn$conn2); ?> to go!)</center></i></b></font><br />
~~~~~~~~~~~<br /><br />
Next 5</font><br /><br />
<font color="#cccccc" size="3"><?php BNF($dbPre$dbPre2$conn$conn2); ?></font>
</center>
Title: Re: Can I put an include file somewhere
Post by: JPDeni on May 14, 2010, 03:23:11 AM
Just the first and last ones need to go. This should work. If it doesn't, let me know and I'll fix it another way.


include "_ott_header.php";
?>
<center><br />
   <font color="#FFFF00" size="4">Block<br /><br />
   ~~~~~~~~~~~<br /><br />
   <font color="#66CC00" size="4"><b><i><center><?php BlockCR($dbPre$dbPre2$conn$conn2); ?><br />(<?php BlockCRDTG($dbPre$dbPre2$conn$conn2); ?> to go!)</center></i></b></font><br />
   ~~~~~~~~~~~<br /><br />
   Next 5</font><br /><br />
   <font color="#cccccc" size="3"><?php BNF($dbPre$dbPre2$conn$conn2); ?></font>
</center>
<?php
Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 03:27:47 AM
Parse error: syntax error, unexpected $end in /home/content/mysite/html/forum/Sources/Load.php(1967) : eval()'d code(48) : eval()'d code on line 11

Guess I should tel you what version I am using aye..lol

SMF 1.1.11
and TP is 1.0 Beta 4
Title: Re: Can I put an include file somewhere
Post by: JPDeni on May 14, 2010, 03:34:09 AM
Try this. (I don't like dealing with embedded html if I can get away from it. It's too confusing.)



include "_ott_header.php";

echo '
<center><br />
   <font color="#FFFF00" size="4">Block<br /><br />
   ~~~~~~~~~~~<br /><br />
   <font color="#66CC00" size="4"><b><i><center>';

BlockCR($dbPre, $dbPre2, $conn, $conn2);

echo
'<br />(';

BlockCRDTG($dbPre, $dbPre2, $conn, $conn2);

echo
'to go!)</center></i></b></font><br />
   ~~~~~~~~~~~<br /><br />
   Next 5</font><br /><br />
   <font color="#cccccc" size="3">';

BNF($dbPre, $dbPre2, $conn, $conn2);

echo '</font>
</center>';

Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 03:37:50 AM
Fatal error: Call to undefined function SponsorLine() in /home/content/mysite/html/forum/Sources/_ott_header.php on line 10

And the forum didnt load, only the blocks loaded.

This is in my php file


<?php
// sessions
session_start();
header('Cache-control: private');

// functions
include('_ott.php');

// check for next in line
SponsorLine($dbPre$dbPre2$conn$conn2);

// validate post
$_POST validate_post($_POST);
?>

Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 03:40:58 AM
mmm, maybe I need to add my other include file in this file to the sources folder as well?

EDIT: YUP IT WORKS :D lol...awesome...thank you soooo mcuh JPDeni : )
Title: Re: Can I put an include file somewhere
Post by: JPDeni on May 14, 2010, 03:53:23 AM
I'm glad you got it figured out. :) I'll mark it solved.
Title: Re: Can I put an include file somewhere
Post by: Z.O.D on May 14, 2010, 03:55:22 AM
 :smitten:


Cant wait to update TP and SMF to this forum, this forum flys!!!!!!!!!Mine is soooo slow!!!!!

I love this forum...