Black Friday = Pricewatch Bekijk onze selectie van de beste Black Friday-deals en voorkom een miskoop.

[PHP5] set_include_path doet het niet

Pagina: 1
Acties:

  • xilent_xage
  • Registratie: Februari 2005
  • Laatst online: 30-10 14:12
Beste tweakers,

Ik zou liever iets leukers doen met mijn zaterdagavond maar vanwege een naderende deadline:

code:
1
2
3
4
set_include_path("/absoluut_pad/directory_1:/absoluut_pad/directory_2");
print_r(get_include_path());
print_r(file_get_contents("test.php"));
print_r(file_get_contents("/absoluut_pad/directory_1/test.php"));


De eerste test.php geeft een no such file of directory, de tweede leest ie wel gewoon goed. Weet iemand waar dit aan kan liggen?

  • _JGC_
  • Registratie: Juli 2000
  • Laatst online: 07:12
Sinds wanneer scant file_get_contents je includepath af? Dat include_path is voor require() en include().

Edit:
http://nl2.php.net/file_get_contents
For all versions prior to PHP 6, this parameter is called use_include_path and is a bool. The flags parameter is only available since PHP 6. If you use an older version and want to search for filename in the include path, this parameter must be TRUE.

[ Voor 60% gewijzigd door _JGC_ op 30-08-2008 20:03 ]


  • xilent_xage
  • Registratie: Februari 2005
  • Laatst online: 30-10 14:12
Verhip. Je hebt gelijk. Opzich zou ik het daarmee wel op kunnen lossen, ware het niet dat het eigenlijke probleem in Smarty zit. Ik include een aantal templates, en daarbij volgt smarty niet de include_path. Ik wil ook niet in de smarty source gaan pielen omdat ik dan weer hetzelfde probleem krijg als ik smarty update.

Kan ik ervoor zorgen dat de include_path voor alles geldt? dus file, file_get_contents enz enz?

  • GlowMouse
  • Registratie: November 2002
  • Niet online
chdir geen optie?

  • xilent_xage
  • Registratie: Februari 2005
  • Laatst online: 30-10 14:12
Ben bang van niet, ik moet met een fallback-systeem werken, waarbij eerst gekeken wordt in directory_1 (custom code), en als de file daar niet bestaat in directory_2 (standaard code). Zie evt dit topic.

  • xilent_xage
  • Registratie: Februari 2005
  • Laatst online: 30-10 14:12
Ok, smarty-probleem opgelost. Mochten anderen met dit probleem zitten:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function wfile_get_template($tpl_name, &$tpl_source, &$smarty) {

    #init
    $includes = explode(":", get_include_path());

    #loop thorugh include paths
    foreach ( $includes as $vinc ) {

        echo $vinc . $tpl_name . "<br />";

        #if file was found
        if ( is_readable($vinc . "/" . $tpl_name) ) {

            #read
            $tpl_source = file_get_contents($vinc . "/" . $tpl_name);

            #return true
            return true;

        }

    }

    #if no match found return false
    return false;

}

function wfile_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty) {

    #init
    $includes = explode(":", get_include_path());

    #loop thorugh include paths
    foreach ( $includes as $vinc ) {

        #if file was found
        if ( is_readable($vinc . "/" . $tpl_name) ) {

            #read
            $tpl_timestamp = filemtime($vinc . "/" . $tpl_name);

            #return true
            return true;

        }

    }

    #if no match found return false
    return false;

}

function wfile_get_secure($tpl_name, &$smarty) { return true; }


function wfile_get_trusted($tpl_name, &$smarty) { return true; }

#register the resource name "wfile"
$smarty->register_resource("wfile", array("wfile_get_template", "wfile_get_timestamp", "wfile_get_secure", "wfile_get_trusted"));


En vervolgens je include:
code:
1
2
{include file="wfile:$_filename"}
{include file="wfile:path/to/file.tpl"}


Bedankt voor het meedenken!

  • Cartman!
  • Registratie: April 2000
  • Niet online
klein tipje: gebruik PATH_SEPARATOR constant voor t scheiden van directory's, is meer portable voor verschillende OS-en.

  • ikke007
  • Registratie: Juni 2001
  • Laatst online: 22-10 21:08
uhhh, zover ik weet kun je in smarty ook een template_include_path oid instellen waarin hij moet zoeken als je templatename.tpl wilt includen vanuit een smarty template... daar heb je dus helemaal geen externe functies oid voor nodig.

Lets remove all security labels and let the problem of stupidity solve itself


  • Patriot
  • Registratie: December 2004
  • Laatst online: 16-11 16:51

Patriot

Fulltime #whatpulsert

ikke007 schreef op zondag 31 augustus 2008 @ 15:02:
uhhh, zover ik weet kun je in smarty ook een template_include_path oid instellen waarin hij moet zoeken als je templatename.tpl wilt includen vanuit een smarty template... daar heb je dus helemaal geen externe functies oid voor nodig.
Dat gaat niet werken, zie xilent_xage in "[PHP5] - set_include_path doet t niet"

  • Johnny
  • Registratie: December 2001
  • Laatst online: 17-11 15:26

Johnny

ondergewaardeerde internetguru

Cartman! schreef op zaterdag 30 augustus 2008 @ 23:47:
klein tipje: gebruik PATH_SEPARATOR constant voor t scheiden van directory's, is meer portable voor verschillende OS-en.
Een forward slash werkt opveral behalve OpenVMS, Classic Mac OS, RISC OS of Symbian welke alledrie niet echt platformen zijn waar je een webserver op wilt draaien of PHP op ontwikkelen.

Aan de inhoud van de bovenstaande tekst kunnen geen rechten worden ontleend, tenzij dit expliciet in dit bericht is verwoord.


  • Voutloos
  • Registratie: Januari 2002
  • Niet online
Johnny schreef op zondag 31 augustus 2008 @ 17:27:
[...]

Een forward slash werkt opveral behalve OpenVMS, Classic Mac OS, RISC OS of Symbian welke alledrie niet echt platformen zijn waar je een webserver op wilt draaien of PHP op ontwikkelen.
Als je, terwijl de generieke oplossing genoemd is, alsnog met een onvolledige implementatie komt aanzetten, heb je je prio's niet op een rijtje staan. Je moet helemaal niet willen denken aan welke OS'en wel of niet werken, gewoon die constante erin klatsen en draaien maar.

{signature}


  • Patriot
  • Registratie: December 2004
  • Laatst online: 16-11 16:51

Patriot

Fulltime #whatpulsert

Johnny schreef op zondag 31 augustus 2008 @ 17:27:
[...]

Een forward slash werkt opveral behalve OpenVMS, Classic Mac OS, RISC OS of Symbian welke alledrie niet echt platformen zijn waar je een webserver op wilt draaien of PHP op ontwikkelen.
PATH_SEPARATOR != DIRECTORY_SEPARATOR.

[ Voor 0% gewijzigd door Patriot op 01-09-2008 13:44 . Reden: typo ]

Pagina: 1