SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42
  1. #26
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Location
    Raleigh, NC
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i get

    "/home/intemp/public_html"

    that dosen't work though, it seems as though theres something before "home" that it's not showing me.

  2. #27
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,933
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course it doesn't work; it is an example. You need to read up on paths!
    Where are :
    /Template/
    /Functions/
    located in relation to the root directory?

  3. #28
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    Boston, MA
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe I'm missing something here, but if you can use the filepath (../) there's no need to use http path. You shouldn't really be including files from remote locations anyway.

  4. #29
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    paths are best if they are relative to server root.. as in most portable and most flexible. completely relative paths, such as ../somepage.php
    is ok but it isnt as good since it will only work with a page that is one level up..
    for instance if you have a scripts in your root directory, and then you have some in an admin directory, if both of those scripts include a script that contains paths in it, the paths will all be screwed up. I'm not sure if i explianed that well, but do a large project and try and use paths that are relative to the current page, and you'll find out how difficult it is. You either have to duplicate tons of code or it just won't work. Your almost guaranteed to have problems unless all of your pages are in the same directory, which will be a pain to manage.

  5. #30
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one of the ways that i typically solve this problem if i'm developing on my own system (not sure if its the only way, or the best way)
    is inlude a global include file in the root directory that defines basic path information.. For instance, if i'm working on a site that has its own domain and everything, i have no easy way of emulating the actual paths on the server with my own machine. I could if i put all the scripts in the root of my server, or went out of my way to create virtual hosts for each.. but thats too much of a pain. So i simply have a test in my global file that checks the domain, and if its my domain name in the url, i set the relative path from my server root as
    $root = $_SERVER['document_root'] . '/<real_domain_name_here>'

    since i have everythin for that site located there
    else its set as
    $root = $_SERVER['document_root'];

    then a simple

    DEFINE("DOC_ROOT", $root);


    then when i want to use a path i just use "DOC_ROOT". /path_to_file

    this makes it easy to create paths that will work from anywhere on the site..

    Note that i wrote this all off the top of my head so it may have errors/flaws. Always test this kind of thing thoroughly before going live.. sometimes you'll end up with an extra slash or so if you arent careful

  6. #31
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is your structure and the exact problem:
    public_html
    |
    \-Functions
    |
    \-Templates
    |
    etc.
    Your $SitePath path returns:
    http://www.intemporelstudios.com/......ate/Header.php

    So to solve the problem the following should be done:
    PHP Code:
    // This is the path to the calling file in the Template directory
    $url_array explode("/"$_SERVER['PHP_SELF']); 
    // This is the path to the Template directory
    array_pop($url_array);
    // This is the path to the public_html directory
    array_pop($url_array);
     
    // And this is the Absolute URL to the public_html directory
    $url 'http://'$_SERVER['SERVER_NAME'].'/'.implode("/",$url_array);
     
    // Include a file from the Functions directory
    require_once($url.'/some_file.php'); 

  7. #32
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Location
    Raleigh, NC
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok I see what you'll mean about the file path thing, So I'm trying to get it so it's not relivite to the file.

    here is what I have and I can't get it to work.
    $_SERVER['DOCUMENT_ROOT'] = /home/intemp/public_html
    $_SERVER['PHP_SELF'] = /~ecensane/TechMagic/index.php

    Before I set those to set as a constant like the code mwolfe suggested I wanted to make sure it worked when I did it in a string typing it out msyelf. so I had this code

    PHP Code:
    require_once("/home/intemp/~ecensane/public_html/TechMagic/Functions/ConnecttoDB.php"); 
    and that didn't work, I'm at a loss mainly on what should be before "/home" cause it seems like there should be a drive letter there but the php code isn't outputting it so o0.

    also none of these strings worked either
    "home/intemp/~ecensane/public_html/TechMagic/Functions/ConnecttoDB.php"
    "home/intemp/public_html/~ecensane/TechMagic/Functions/ConnecttoDB.php"

    and the error that I got was that the file could not be found, so it's nothing with the syntax of my code.

  8. #33
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a drive letter? you seem a bit confused.
    what kind of system are you using, windows or linux/unix?
    linux/unix doesnt use drive letters. All paths are relative to the file system root, which is /
    so you can get to any folder from there, no need for drive letters. If there are multiple drives, the drive can be mounted into the current file system into another folder.

    also, are you running this from your hosts server or on a local server?

  9. #34
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Location
    Raleigh, NC
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm running this from a host linux server.

    I figured it out with $_SERVER["SCRIPT_FILENAME"], thanks eveyrone.
    Last edited by ecensane; Oct 9, 2005 at 12:39.

  10. #35
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't have to go to:
    home/intemp/~ecensane/public_html/TechMagic/Functions/ConnecttoDB.php
    if your Template directory is at:
    home/intemp/~ecensane/public_html/TechMagic/Template
    You have to go to une directory up like this:
    ../Functions/ConnecttoDB.php

  11. #36
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Location
    Raleigh, NC
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I get links to work using the file path method?

    when it tries to do "/home/ecesane/public_html/....", it comes up "www.intemporelstudios.com/home/ecensane" which isn't wokring...

  12. #37
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Calculating that:
    $_SERVER['PHP_SELF'] = /~ecensane/TechMagic/index.php

    PHP Code:
    $url_array explode("/"$_SERVER['PHP_SELF']); 
    array_pop($url_array); // Removes index.php
    $url=implode("/",$url_array); // equals /~ecensane/TechMagic
     
    require_once($url."/Functions/YOUR_FILE.PHP"); // equals /~ecensane/TechMagic/Functions/YOUR_FILE.PHP 

  13. #38
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Location
    Raleigh, NC
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by REMIYA
    Calculating that:
    $_SERVER['PHP_SELF'] = /~ecensane/TechMagic/index.php

    PHP Code:
    $url_array explode("/"$_SERVER['PHP_SELF']); 
    array_pop($url_array); // Removes index.php
    $url=implode("/",$url_array); // equals /~ecensane/TechMagic
     
    require_once($url."/Functions/YOUR_FILE.PHP"); // equals /~ecensane/TechMagic/Functions/YOUR_FILE.PHP 
    That still dosen't help, I need it to start at home becuase if i like to it with the http path then it dosen't include the variables and the functions, how can i get it to just not put in www.intemporelstudios.com/

  14. #39
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $SitePath "http://www.intemporelstudios.com/~ecensane/TechMagic"
    $url_array=explode("/",$SitePath); 
    $url_array array_slice($url_array3); // Removes "http:","","www.intemporelstudios.com"
    $url implode("/",$url_array); // Returns "/~ecensane/TechMagic" 

  15. #40
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Location
    Raleigh, NC
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no I don't think you understand, I'm not using the http path anymore I'm using

    $SitePath = "/home/ecensane/public_html/TechMagic";

    when I use the link

    <a href = \"" . $SitePath . "/index.php">home</a>

    it tries to go to this url

    http://www.intemporelstudios.com//ho...agic/index.php

    how do I get around this, I can't use "../" becuase I'm calling this file from diferent levels inside the folder structure like mwolfe said.

  16. #41
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,933
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You cannot use an http path with include or require! If you want to run your stuff at home install PHP on your local machine.

  17. #42
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman
    You cannot use an http path with include or require! If you want to run your stuff at home install PHP on your local machine.
    Yes, you can-- you can't, however, access any PHP from the code, only the html outputted by it.

    You're getting confused, I think, ecensane.

    You need to INCLUDE with the file path, at set the SitePath var with the http path.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •