Ahoj, mám vytvořený soubor header.inc a footer.inc . Když otevřu stránku v kořenovém adresáři, tedy www.stranka.cz/index.php a v ní je toto
<?php
include('recenze/hlavicka.inc');
?>
tak to funguje. Ovšem pokud je stránka www.stranka.cz/clanky/recenze/index.php , tak to napíše tuto chybu
Warning: include(recenze/hlavicka.inc) [function.include]: failed to open stream: No such file or directory in /home/free/ic.cz/f/figa/root/www/clanky/recenze/index.php on line 2
Warning: include() [function.include]: Failed opening 'recenze/hlavicka.inc' for inclusion (include_path='/usr/share/php/smarty/libs:/usr/share/fpdf:/usr/share/php/:.') in /home/free/ic.cz/f/figa/root/www/clanky/recenze/index.php on line 2
Co je špatně?Předem děkuji za odpovědi.
Fórum › PHP
Nefunkční include()

tak se treba vrat o adresar nize:
<?
include "../../header.inc";
?>
Ted by ti to melo fungovat.
Pozor! pokud se ti koncovka .inc neodesila na server, davej si na to pozor. Uz se mi to jednou stalo, mel se v header php kody a ty mi nekdo hacknul. Tak ti radim dobre dej koncovku php.
tak ale zase sou s tym dalsi problemy. treba kdyz mas jako ja v header.inc nejaky include. nejlepsi je mit v hlavnim adresari index.php a k jinym souborum vzdycky pres otaznik >> index.php?clanek=1
nebo si precti na http://www.jakpsatweb.cz o .htaccess mod rewrite. ale na ic.cz to nefunguje.
je to ze si uzivatel zavola treba soubor /Clanek--01--neco-nadpis.php
a server to vrati jako index.php?clanek=01&neco=nadpis
podle toho jak to chces
zapis by mel byt. rekl bych ze to takhle bude lepsi nez s temi zavorkami.. sice je mozne ze zavorky se daji asi pouzit ale toto je prehlednejsi a jistejsi...
include "./index.php";
PS.: ./ - označuje skok do kořenového adresáře
../ - označuje skok o jednu úroveň zpět
To psenik : nejsem si moc jisty, ale ./ znamena aktualni adresar ne? do korenoveho adresare by mohlo byt jen lomitko
vsak ti rikam ze kdyz napises include "soubor.inc"; tak on si mysli, ze ten soubor je v tom adresari, kde je ten php skript. chapes? takze kdyz chces includovat soubor, ktery je o uroven vys, tak pouzij ../
o dve slozky vys: ../../
o tri slozky vys: ../../../
atakdale...
takze kdyz mas hlavnim adresari soubor hlavicka.inc a mas clanek v /recenze/clanky/idnex.php
tak si napis do hlavicka.inc obrazky s absolutni cestou + http:// (například: <img src="http://figa.ic.cz/obrazky/img.gif">)
a do index.php napis:
<? include "../../hlavicka.inc"; ?>
Tvůj obsah
<? include "../../paticka.inc"; ?>
A bude ti to fungovat!
Děkuji už to funguje. Mám tu ale další ovšem velmi podobný problém. Script v souboru hlavicka.inc funguje jen pokud je v kořenovém adresáři. Obrázky na které to odkazuje jsou v /numers/x.gif a soubor je v /recenze/sw/program/soubor.php. Proč to nefunguje:
function obrazkoveDatum($datum) {
$datum = str_replace('.', 'x', $datum);
for($i = 0;$i < strlen($datum);$i++){
if(file_exists('http://figa.ic.cz/numers/'.$datum[$i].'.gif'))
echo '<img src="http://figa.ic.cz/numers/'.$datum[$i].'.gif">';
else
echo $datum[$i];
}
}
Předem děkuji za odpovědi.
jestli to není tím, že tu adresu souboru máš zobrazenou přes http adresu... zkus jen napsat
function obrazkoveDatum($datum) {
$datum = str_replace('.', 'x', $datum);
for($i = 0;$i < strlen($datum);$i++){
if(file_exists('/numers/'.$datum[$i].'.gif'))
echo '<img src="http://figa.ic.cz/numers/'.$datum[$i].'.gif">';
else
echo $datum[$i];
}
}
Jde mi o toto z manuálu:
file_exists
(PHP 3, PHP 4 , PHP 5)
file_exists -- Zjistí, zda soubor existuje
Popis
bool file_exists ( string filename)
Vrací TRUE, pokud soubor specifikovaný pomocí filename existuje, jinak FALSE.
file_exists() nefunguje na vzdálených souborech; soubor k ověření musí být přístupný prostřednictvím filesystému serveru.
Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/numers/2.gif) is not within the allowed path(s): (.:/home/ic/:/home/free/:/disk1/home/ic/:/disk1/home/free/:/tmp:/home/yousers/:/usr/share/php/:/usr/share/fpdf/:/usr/share/fonts/:/usr/share/php/jpgraph/:/usr/share/php/:/var/lib/php5) in /home/free/ic.cz/f/figa/root/www/clanky/hlavicka.inc on line 158
2
Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/numers/6.gif) is not within the allowed path(s): (.:/home/ic/:/home/free/:/disk1/home/ic/:/disk1/home/free/:/tmp:/home/yousers/:/usr/share/php/:/usr/share/fpdf/:/usr/share/fonts/:/usr/share/php/jpgraph/:/usr/share/php/:/var/lib/php5) in /home/free/ic.cz/f/figa/root/www/clanky/hlavicka.inc on line 158
6
Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/numers/4.gif) is not within the allowed path(s): (.:/home/ic/:/home/free/:/disk1/home/ic/:/disk1/home/free/:/tmp:/home/yousers/:/usr/share/php/:/usr/share/fpdf/:/usr/share/fonts/:/usr/share/php/jpgraph/:/usr/share/php/:/var/lib/php5) in /home/free/ic.cz/f/figa/root/www/clanky/hlavicka.inc on line 158
4
Děkuji, ale už jsem to s Lookovou pomocí vyřešil.
function file_external_exists($url)
{
$headers = @get_headers($url);
if(preg_match("|200|",$headers[0]))
return(true);
else return(false);
}
function obrazkoveDatum($datum) {
$datum = str_replace('.', 'x', $datum);
for($i = 0;$i < strlen($datum);$i++){
if(file_external_exists('http://figa.ic.cz/numers/'.$datum[$i].'.gif'))
echo '<img src="http://figa.ic.cz/numers/'.$datum[$i].'.gif">';
else
echo $datum[$i];
}
}

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Mysql a (pravdepodobne nefunkcní diakritika)nefunkcni — založil Alex
Include z GET — založil matouch
Moderátoři diskuze