Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> require i include
mat_1200
post
Post #1





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Mam problem z funkcją require i include. Mam oto takie katalogi:

fragments

tables
_____________

w folderze 'tables' jest plik 'tables_news.php'

w folderze 'fragments' jest pelno plikow a jeden z nich to 'news.php'

W pliku 'tables_news.php' chce wstawić funkcję require tak by w nawiasie był plik 'news.php'

Próbowałem wpisać require'fragments/news.php'; ale nie dziala.
wyskoczył błąd:
Cytat
Warning: main(fragments/news.php): failed to open stream: No such file or directory in c:\usr\apache\httpd\html\www\site kod\php\tables\table_news.php on line 1

Fatal error: main(): Failed opening required 'fragments/news.php' (include_path='.') in c:\usr\apache\httpd\html\www\site kod\php\tables\table_news.php on line 1


Poradzcie coś...
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


../fragments/news.php
Go to the top of the page
+Quote Post
tommy4
post
Post #3





Grupa: Zarejestrowani
Postów: 288
Pomógł: 12
Dołączył: 2.12.2005

Ostrzeżenie: (0%)
-----


Myślę, że aby "przesunąć" się o jeden poziom niżej trzeba dodać "../" przed ścieżką, czyli np. w Twoim przypadku: ../fragments/news.php
Go to the top of the page
+Quote Post
mat_1200
post
Post #4





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Dzieki
Go to the top of the page
+Quote Post
-beginner-
post
Post #5





Goście







ale ale..jaka jest właściwie różnica między funkcją include a require. Na pozór wyglądają tak samo. Tlumacenie jest mgliste a piszą ze pymylenie tych dwu funcji moze być dramatyczne w skutkach. Dlaczego ?
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




jesli ten opis jest dla ciebie mglisty to ja nie wiem jak ci lepiej to wytlumaczyc
http://pl.php.net/manual/pl/function.include.php
Go to the top of the page
+Quote Post
-beginner-
post
Post #7





Goście







dziex.
Ten opis jest przede wszystkim niewystarczajacy. Czytalem wiele opisów tych rożnic i dalej nie wiem nic. Jedni pisza ze require realizuje sie przed parsowaniem drudzy ze funkcja require zostaje zastąpiona plikiem na który wskazuje podczas gdy include działa bardziej jako odgałęzienie realizacji skryptu. ....hmmm liczmy na to ze znajdzie sie facet który potrafi to wytłumaczyc uzywając layman's language.
Mimo wszystko dzięki (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
pozdro (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
FiDO
post
Post #8





Grupa: Przyjaciele php.pl
Postów: 1 717
Pomógł: 0
Dołączył: 12.06.2002
Skąd: Wolsztyn..... Studia: Zielona Góra

Ostrzeżenie: (0%)
-----


Wg mnie w manualu jest napisane bardzo jasno czym to sie rozni:
Cytat("manual")
Obydwie instrukcje są identyczne w każdym szczególe, z wyjątkiem obsługi błędów. include() generuje błąd typu Warning, podczas gdy require() generuje błąd Fatal Error
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #9





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


Roznia sie tylko typem wyrzucanego bledu w przypadku braku pliku: notica/warning.
EDIT: troche pomylilem bledy (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował dr_bonzo 18.12.2005, 20:51:01
Go to the top of the page
+Quote Post
mat_1200
post
Post #10





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.12.2005

Ostrzeżenie: (0%)
-----


Oblookajcie moj topic http://forum.php.pl/index.php?showtopic=38915
Go to the top of the page
+Quote Post
-beginner-
post
Post #11





Goście







hmmm... sam nie wiem co o tym myslec /uparty (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) /
A próbowaliście kiedys zastosowac require() w pętli ?

http://www.70.pl/main.php?id=101&ktory_art=81
http://www.alt-php-faq.org/local/78/
i najważniejsza (IMG:http://forum.php.pl/style_emoticons/default/blink.gif)
http://www.jwweb.com/20010629.html
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #12





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


Manual: "The require() statement includes and evaluates the specific file."
"require() and include() are identical in every way except how they handle failure"

  1. <?php for ( $i = 0; $i < 3; $i ++ )
  2. {
  3. include 'a_' . $i . '.php';
  4. }?>


  1. <?php for ( $i = 0; $i < 3; $i ++ )
  2. {
  3. require 'a_' . $i . '.php';
  4. }?>


oczywiscie utworz pliki 'a_*.php' -- rezultat: wsyzstkie 3 zostaluy zaincludowane/zarequirowane.
Go to the top of the page
+Quote Post
-beginner-
post
Post #13





Goście







Chyba, powtarzam CHYBA.....czuje sie pokonany:)
Dziex i (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) i Dobranocka (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.08.2025 - 00:04