Results 1 to 8 of 8

Thread: Stupid PHP question     submit to reddit submit to twitter

  1. #1
    House Azazael
    Join Date
    Mar 2007
    Posts
    1,641
    BG Level
    6
    FFXI Server
    Fenrir

    Stupid PHP question

    It is late and I am sure I am over looking something, so hopefully you guys can help.

    I am working on a website for a friend and here is how I would like to set it up.

    root
    root/includes (has my image directory, stylesheets directory, and include files)
    root/otherdirectory (with multiple subdirectories)

    The problem I am having is that I can get pages to display fine from the root, but when I go to the otherdirectory it is having problems getting the include files right.

    am I just really tired and this isn't possible. or do I need to do something differently?

  2. #2
    New Spam Forum
    Join Date
    May 2010
    Posts
    159
    BG Level
    3
    FFXI Server
    Lakshmi

    what path are you using in otherdirectory to call the files in the includes folder? something like ../includes?

    p.s. not a php expert at all.

  3. #3
    Hyperion Cross
    Join Date
    Jan 2007
    Posts
    8,883
    BG Level
    8
    FFXIV Character
    Kai Bond
    FFXIV Server
    Gilgamesh

    From my previous experience I only use include to directly shove (add?) something onto part of my website, not actually "include" whole directories and treat them as it's on the root.

    Can you tell me what you are trying to do overall?

  4. #4
    House Azazael
    Join Date
    Mar 2007
    Posts
    1,641
    BG Level
    6
    FFXI Server
    Fenrir

    well I think I have my problem solved.

    Is what I was trying to do was to reference two style sheets, two includes, and an image; no matter where I was in the directory structure.

    The way I fixed the problem was to add as many ../ as I would need at the max depth. So since I knew I was going to need access to some of the files from 3 deep, I have 3 ../ preceding my references. The big problem I was running into is that my include files were referencing the image and stylesheets. Since they were at the same level I didn't think I needed to add a bunch of ../ It turns out though, that it was trying to add the files from the original calling file level, and not the include file level.

    Not sure if that made enough sense or not

  5. #5
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    I believe PHP always base the file path from the location the currently run file is at. As such, if you do, for example, a require(include/stylesheet.xls) for the layout of the page, the stylesheet.xls file would also need the filepath starting from the file that runs it. As such, it is usually best to include the full filepath for all files that are opened through another file.

    Remember, when you use the require() command anywhere on your page, it pretty much replaces require() with the full text from the file it opens. As such, it would try to use the file path from that file, causing an error.

  6. #6
    PROM KING OF
    SHOWDOWN HIGH

    Join Date
    Dec 2008
    Posts
    65
    BG Level
    2

    From php.net:

    "Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() will finally check in the calling script's own directory and the current working directory before failing. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error."

    include_path is a configuration option set in your php.ini . The safest way to include things is to use absolute paths, or failing that, define your include_path in php.ini and put everything you need included in that directory. That way, you can just say require_once('vars.php') and no matter your CWD or the directory of the file you're calling require_once() from, it'll look first in your include_path.

  7. #7
    House Azazael
    Join Date
    Mar 2007
    Posts
    1,641
    BG Level
    6
    FFXI Server
    Fenrir

    php.ini is site wide correct, you can't override it for a local area.

  8. #8
    PROM KING OF
    SHOWDOWN HIGH

    Join Date
    Dec 2008
    Posts
    65
    BG Level
    2

    You can override it on a per-script basis with ini_set(), and some variables can be overridden on a per-directory basis with .htaccess files.

    http://www.php.net/manual/en/ini.list.php This is a list of all the configuration options. The ones you can override with ini_set() are listed as PHP_INI_USER, and the ones you can change with .htaccess directives are listed under PHP_INI_PERDIR

Similar Threads

  1. Really, really stupid mouse question...
    By TybudX in forum Tech
    Replies: 2
    Last Post: 2008-07-27, 13:42