What is the path to a file that php code calls?

Permalink
Hi, there,

I found a randon quote-type script that calls a flat file which I'd create with my quotes in it.

What is the path of a standard block? Meaning what path do you have to use in order to call a file from your own code?

Thanks a lot, and have a good day, all,

- Paul

 
jordanlev replied on at Permalink Reply
jordanlev
Is this like a php library file with functions you're going to call from your own code? Or is it a file that needs to be included by the browser (like this is a self-contained script that outputs html)?

If the former, you want to drop it in your site's "libraries" folder and then use the Loader, like this:
Loader::library('my_file_name'); //Note that you don't put the ".php" extension here


If the latter, then you want to drop it in your theme folder and use "$this->getThemePath()" in your template to include it. Or if you are making a block, you can put it in your block's folder and then get the url to it from your block controller like this:
$bv = new BlockView();
$bv->setBlockObject($this->getBlockObject());
$bv->getBlockURL();


HTH!
TheAngelGuy replied on at Permalink Reply
It does help, but still being new, I'm wondering if I can't just have a literal call.

Here's the code -

(The file in question is "quotes.txt".)

<?
$r_array=file('quotes.txt');
shuffle($r_array);
echo $mQuotePath[0];
echo $r_array[0];
?>

From what I had to do in Drupal, I know that it might not be the root path that the page generation system might be looking at.

Can I just use /(concrete5root)/quotes.txt and will it work?

Or do I even have to use a literal path?

I guess I'm asking that if I used that code as stated above, what directory will it look in by default for that text file?

Thanks so much, and sorry if this is confusing.

Have a good one,

- Paul
jordanlev replied on at Permalink Reply
jordanlev
Well, you can use:
__FILE__

to get the path to the current file, and build a relative path from there (that's just a normal php thing -- has nothing to do with C5 specifically).

But since you're using a CMS, a better way to do this would be to write a block that allowed users to enter their own list of quotes. Could just be a text area that they paste quotes into (one per line), saved to the database as a TEXT field. See the tutorials in the docs about building blocks -- this would be relatively straightforward and a good learning exercise.

-Jordan