SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How do I get root folder?

    I have a structure folder as follow:



    C:\xampp\htdocs\demo\the-affable-bean\web-inf\include
    C:\xampp\htdocs\demo\the-affable-bean\web-inf\view
    In clude folder, I have two files are header.php and footer.php. In the files of view, I include them into. In index.php, I do the same.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"

    <
    html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
    <
    head>
        <
    meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <
    link rel="stylesheet" type="text/css" href="../../css/affablebean.css" />
        <
    title>Affable Bean</title>
    </
    head>
    <
    body>
        <
    div id="main">
            <
    div id="header">
                <
    div id="widgetBar">
                    <
    div class="headerWidget">
                        [
    language]
                    </
    div><!-- end .headerWidget -->
                    
                    <
    div class="headerWidget">
                        [
    cart]
                    </
    div><!-- end .headerWidget -->
        
                    <
    a href="#">
                        <
    img src="../../img/logo.png" id="logo" alt="" />
                    </
    a>
                    
                    <
    a href="index.php">
                        <
    img src="../../img/logoText.png" id="logoText" alt="" />
                    </
    a>
                </
    div><!-- end #widgetBar -->
            
    </div><!-- end #header --> 
    As all you know, when we can access in upper folder by use ../ to do something. In the view folder, I can include file css in css folder by

    ../../css/affablebean.css
    (1)

    But in the file index.php, I can't use (1) to access css file in css folder like this. I feel like take root folder to access any folders and files. If I use ../, and I have a lot of folders, it's very disavantage. How can I do this with php? I use $_SERVER['DOCUMENT_ROOT'] but it's not work.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by greedyman View Post
    I use $_SERVER['DOCUMENT_ROOT'] but it's not work.
    Even though you are using XAMPP, the root folder on your local machine is not your site's root folder. However, you can set upyour computer to work the way you want by setting up virtual hosts:

    http://sawmac.com/xampp/virtualhosts/


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
  •