PDA

View Full Version : php include problem



alexdog1805
01-13-2009, 02:16 PM
I have a file.html that i want to include in other files, but the problem is that it works only in pages that are i root but files are in subdiretory for example root/images it don't works even if i pun ../../file.html, this is the code:


<div id="Layer60"><?php include('../../meniu-principal.html'); ?></div>
<div id="Layer62"><?php include('../../reclama.html'); ?></div>
<div id="Layer63"><?php include('../../cod-postal.html'); ?></div>
<div id="Layer64"><?php include('../../meteo.html'); ?></div>
<div id="Layer65"><?php include('../../poza-zilei.html'); ?></div>
<div id="Layer66"><?php include('../../Bancuri.html'); ?></div>
<div id="Layer67"><?php include('../../meniu-bancuri.html'); ?></div>
<div id="Layer68"><?php include('../../horoscop.html'); ?></div>

bluewalrus
01-13-2009, 02:23 PM
So you have some php working in your file.html?? I don't know how that's working but it should be file.php. Since your using php not just html in it, that may be your problem.

Twey
01-13-2009, 02:35 PM
Not enough information was provided. Where is the included file? Where is the including file?

alexdog1805
01-13-2009, 02:35 PM
So you have some php working in your file.html?? I don't know how that's working but it should be file.php. Since your using php not just html in it, that may be your problem.

no man, the php code i put in an .php file, but in that .php file i want to include that .html files.

alexdog1805
01-13-2009, 02:50 PM
Not enough information was provided. Where is the included file? Where is the including file?

the included file is on root and the including file is root/images/funny and in the inclding file i put the code: <?php include("../../horoscop.html"); ?> but the including file is a .php page only the included file is a .html file.

Twey
01-13-2009, 04:19 PM
That should be fine. What do you mean that it 'doesn't work'? What error message(s) do you get? If none, put error_reporting(E_ALL); at the top of your script.

alexdog1805
01-13-2009, 06:09 PM
That should be fine. What do you mean that it 'doesn't work'? What error message(s) do you get? If none, put error_reporting(E_ALL); at the top of your script.

it doesn't apears me nothing. Just watch http://otisweb.uv.ro and watch http://otisweb.uv.ro/Imagini/Funny/Funny.php and you'll see the difference. It doesn't appears me the menu up in the Funny.php page and that black titles which appears only at the index page.

alexdog1805
01-13-2009, 08:24 PM
I think the proble is the placement of " because if i write include("../../file.html") the computer consider that ../../file.html is the name of the file not file.html that is 2 directory level up, on root.

alexdog1805
01-13-2009, 08:25 PM
I think the problem is the placement of ditto marks because if i write include("../../file.html") the computer consider that ../../file.html is the name of the file not file.html that is 2 directory level up, on root.But if I write include(../../"file.html") don't recognize all the page:)) what should be the problem

bluewalrus
01-14-2009, 01:46 AM
Error messages:

Warning: include(f1/f2/meniu-principal.php) [function.include]: failed to open stream: No such file or directory in /home/www/free/uv.ro/otisweb.uv.ro/Imagini/Funny/Funny.php on line 860

Warning: include() [function.include]: Failed opening 'f1/f2/meniu-principal.php' for inclusion (include_path='.:./inc:/home/www/lib:/home/www/lib/pear:/home/www/lib/pear/DB:/home/www/lib/nusoap:/home/www/lib/phrame:/home/www/lib/toplabs:/allowrun:') in /home/www/free/uv.ro/otisweb.uv.ro/Imagini/Funny/Funny.php on line 860

This will never be valid (../../"file.html"). It could be ("../../file.html") or (../../file.html) or possibly ("/../../file.html") or (/../../file.html). I'm not that sure or familiar with includes. I'm pretty certain Twey will know though so wait for a response from him or Nile or someone that knows php a bit better. I'm still learning it as well.

Dirt_Diver
01-14-2009, 02:51 AM
Why don't you just rename the html file with a php extension?

Try this also...

You have
<div id="Layer60"><?php include('../../meniu-principal.html'); ?></div>

make it:
<div id="Layer60"><?php include("../../meniu-principal.html"); ?></div>

Single quotes from my understanding are used to display a literal. Because you are trying to include a page I would think you want to use double quotes.

Twey
01-14-2009, 06:13 AM
No, include(../../file.html) isn't valid either. Syntactically, include() is just a function to which you pass the path to the include, as a string. Strings must always be wrapped in quotation marks (PHP does make an exception for undefined constants, but you shouldn't rely upon it).

According to these errors you're doing include('f1/f2/meniu-principal.php'), not include('../../file.html').

Single quotes are used to express a literal string — no special operations will be performed on it, like escape code interpretation or variable interpolation. "$a\n" contains the value of the variable $a followed by a newline, but '$a\n' contains a dollar sign, the letter 'a', a backslash, and the letter 'n'. It's faster, so it should be used where no fancy stuff is required.

You should also note that your site's code breaks an awful lot of good Web development practices (http://dynamicdrive.com/forums/showpost.php?p=158839&postcount=1337).

alexdog1805
01-14-2009, 09:49 AM
can be the problem that the version of php that hosting company uses is older?

Twey
01-14-2009, 10:21 AM
No. PHP has supported include() pretty much forever.