Page 1 of 1
[Solved] How to include a file
Posted: Fri Aug 05, 2011 11:23 am
by Ignatius881
Hello.
I have some problems with de include/require_once function. For example, I've a folder called "root", and there is a subfolder in it called "test". In "root" there is a file, main.php, and in "test" there are many files which include main.php. They have this:
But it doesn't work, and I don't know why. How can I include a file which is in a higher folder?
Thanks.
Re: How to include a file
Posted: Fri Aug 05, 2011 11:51 am
by Dodon
if these exist:
/main.php
/test/page.php
and in page.php you place the include like you did above it should work.
Do you get an error?
Re: How to include a file
Posted: Fri Aug 05, 2011 12:04 pm
by Ignatius881
No, there isn't an error.
It's rilated to gettext. Here is page.php:
Code: Select all
<?php require_once("../local.php"); ?>
<?php
echo _("Hello world");
?>
And here is main.php:
Code: Select all
<?php
$locale = "es_ES.utf8";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");
?>
So, if I open page.php with my browser, it should show the text in Spanish, and by writing ?locale=en_GB, it's in original version. This works if both files are in the same folder, but not when they are in different folders, because it only shows the original version, not the translated one.
Of course, there is also the "locale" folder, with .mo and .po, etc.
Re: How to include a file
Posted: Fri Aug 05, 2011 1:04 pm
by social_experiment
Can you show what the complete directory setup looks like?
Re: How to include a file
Posted: Fri Aug 05, 2011 1:08 pm
by Ignatius881
social_experiment wrote:Can you show what the complete directory setup looks like?
/main.php
/locale/es_ES/LC_MESSAGES/messages.mo
/locale/es_ES/LC_MESSAGES/messages.po
/test/page.php
And page.php with <? require_once("../main.php"); ?>
Re: How to include a file
Posted: Fri Aug 05, 2011 1:12 pm
by social_experiment
Code: Select all
#try
<?php require_once("/../main.php"); ?>
Re: How to include a file
Posted: Fri Aug 05, 2011 1:18 pm
by Ignatius881
social_experiment wrote:Code: Select all
#try
<?php require_once("/../main.php"); ?>
It shows an empty page, with no text.
Re: How to include a file
Posted: Fri Aug 05, 2011 1:56 pm
by social_experiment
Odd that require_once('../main.php') isn't working and even stranger that no error is reported. This (to me) indicates that there isn't a problem with the including of the file but something inside the file isn't working correctly.
Re: How to include a file
Posted: Fri Aug 05, 2011 2:17 pm
by Ignatius881
I think that everything is correct and should work correctly. I don't know.
Why does it not work if both files are separated, and does it work if both files are together?
Re: How to include a file
Posted: Sat Aug 06, 2011 2:50 am
by social_experiment
You might have to contact the person/s who created the code and inform them of the problem. It's possible that other people have had / are having similar problems. Maybe they have the solution in an FAQ area.
Re: How to include a file
Posted: Sat Aug 06, 2011 6:01 am
by Ignatius881
social_experiment wrote:You might have to contact the person/s who created the code and inform them of the problem. It's possible that other people have had / are having similar problems. Maybe they have the solution in an FAQ area.
In fact, I'm helping him with that project, we're friends
But it doesn't matter, I've found a solution thanks to an IRC channel. Thanks anyway for your help
