/    Sign up×
Community /Pin to ProfileBookmark

How to use DIRNAME function?

I put this:

[code=php]<?require_once dirname(‘menupart.php’) . ‘../../menu.php’;?>[/code]

Why it does not show menu?
As I understand it wil [B]recognise en-GB/menu/ directory where is file [/B]menu.php and it will go back to root with ../../ and show relative path.

Is this correct?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiAug 06.2009 — The code you have posted doesn't really make sense. Since menupart.php is a relative path (relative to the current directory), dirname is always going to be the current directory. So you may as well just write:

[code=php]<?php require_once '../../menu.php' ?>[/code]
Copy linkTweet thisAlerts:
@toplisekauthorAug 06.2009 — Is this correct:
[code=php]<?require_once dirname() . '../../menu.php';?> [/code]

How to do correct with function dirname()?
Copy linkTweet thisAlerts:
@ryanlundAug 06.2009 — Dirname simply returns the name of the directory of the file you specify....so no, it doesnt make any sence at all....

we cant really tell you the code you need without knowing the file structure tho =
Copy linkTweet thisAlerts:
@toplisekauthorAug 06.2009 — I will be specific:

I have included file UP for two folders

File where is included this file is also UP two folders from ROOT but with different folder name.

this is structure.
Copy linkTweet thisAlerts:
@MindzaiAug 06.2009 — I still don't understand. Can you post the three relevant absolute paths then it might be easier to understand what you mean.

  • 1. The absolute path to the script containing this code

  • 2. The absolute path to menupart.php

  • 3. The absolute path to menu.php
  • Copy linkTweet thisAlerts:
    @toplisekauthorAug 06.2009 — Sorry not to be clear:

    I have the following issue:

    1. I would like to test file index.php in ROOT directory and include menu:

    FTP path is /public_html/mydomain

    2. I would like to include menu file using function like:
    [code=php]
    <?php require_once dirname(__FILE__) . '/../../mymenu.php' ?>;
    [/code]

    3. Absolute path for the included file is:

    en-GB/menu/mymenu.php from ROOT

    I hope I helped more to be clear.

    [I]1. I assume the following would solve this but do not know why is not showing menu:

    [code=php]
    <?PHP @require_once dirname(__FILE__).'/en-GB/menu/mymenu.php'; ?>
    [/code]

    2. What should be at the top of each included files to work links in correct way?[/I]
    Copy linkTweet thisAlerts:
    @MindzaiAug 06.2009 — Right I think there's a confusion in terminology here but let me see if I understand.

    You have a file, index.php, which lives in:

    public_html/mydomain/index.php

    You have the following file which you'd like to include:

    public_html/mydomain/en-GB/menu/mymenu.php

    If I've understood correctly, you are going the wrong way in the directory tree. You will need to do this:

    [code=php]require_once 'en-GB/menu/mymenu.php';[/code]
    Copy linkTweet thisAlerts:
    @toplisekauthorAug 06.2009 — ok, if you have path system and many pages.

    What would you put at the top of mymenu.php to see this file and links will work from mymenu.php?

    $_PATHROOT= $_SERVER['DOCUMENT_ROOT']."/";

    Strange that <?PHP @require_once($_PATHROOT."en-GB/menu/mymenu.php");?>


    will not work if I include variable page at the top on ALL files.

    If I exclude it will not work mymenu.php. When using

    $_
    PATHHOME="http://" . $_SERVER['HTTP_HOST']."/"; it will work if I put variable page at the top.
    ×

    Success!

    Help @toplisek spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...