path problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yang Li Ke

    path problem

    Hello all.

    i have some fopen problems with paths.

    I have a script which does fopen("template s/file.php","w"); in a script
    called f.php inside a folder named /folder

    Sometimes i call this script from /root and sometimes from /root/folder

    so i dont know how to make sure that it will always do the fopen to the file
    in the /folder/templates/

    Anyone can give me some help ?

    --
    Yang


  • Jochen Buennagel

    #2
    Re: path problem

    Yang Li Ke wrote:[color=blue]
    > I have a script which does fopen("template s/file.php","w"); in a script
    > called f.php inside a folder named /folder
    >
    > Sometimes i call this script from /root and sometimes from /root/folder
    >
    > so i dont know how to make sure that it will always do the fopen to the file
    > in the /folder/templates/[/color]

    you can use fopen(dirname(_ _FILE__)."/templates/file.php","w");

    __FILE__ is always the full path of the current file, so in your case it
    will be "/folder/f.php", and dirname(__FILE_ _) will evaluate to "/folder"

    Hope this helps,

    Jochen

    Comment

    • Tom Thackrey

      #3
      Re: path problem


      On 4-Jan-2004, "Yang Li Ke" <yanglike@sympa tico.ca> wrote:
      [color=blue]
      > i have some fopen problems with paths.
      >
      > I have a script which does fopen("template s/file.php","w"); in a script
      > called f.php inside a folder named /folder
      >
      > Sometimes i call this script from /root and sometimes from /root/folder
      >
      > so i dont know how to make sure that it will always do the fopen to the
      > file
      > in the /folder/templates/
      >
      > Anyone can give me some help ?[/color]

      use the full path
      fopen("/root/folder/templates/file.php",...

      --
      Tom Thackrey

      tom (at) creative (dash) light (dot) com
      do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

      Comment

      • CountScubula

        #4
        Re: path problem

        "Yang Li Ke" <yanglike@sympa tico.ca> wrote in message
        news:DyXJb.510$ D21.198298@news 20.bellglobal.c om...[color=blue]
        > Hello all.
        >
        > i have some fopen problems with paths.
        >
        > I have a script which does fopen("template s/file.php","w"); in a script
        > called f.php inside a folder named /folder
        >
        > Sometimes i call this script from /root and sometimes from /root/folder
        >
        > so i dont know how to make sure that it will always do the fopen to the[/color]
        file[color=blue]
        > in the /folder/templates/
        >
        > Anyone can give me some help ?
        >
        > --
        > Yang
        >
        >[/color]

        try using the full path like this
        fopen("/www/website/templates/file.php","w");

        I tend to do this when this problem comes along
        $absPath = "/www/website"; // I put this in a master include file, say
        config.php

        fopen("$absPath/templates/file.php","w"); // then this works


        --
        Mike Bradley
        http://gzen.myhq.info -- free online php tools


        Comment

        Working...