php tell me directory

Posted on 2012-08-17
Last Modified: 2012-08-18
does not work

tells me filename

but I want the directory that I am in (minus filename)
Question by:rgb192

    Accepted Solution

    You have a few options on this one...

    The first is if the code you are using IS in the directory of the file you are using then there is no need to list the directory.....

    Say you are in the directory "html/www/testDIR/"
    and you had a file in it: "html/www/testDIR/test.php"

    then you can easily in that test.php file declare the file you need without the current directory like so:
    $filename = "testfilename.php";

    and that will be the same as: "html/www/testDIR/testfilename.php"

    or use an alternative like so:

    // current directory
    echo getcwd();

    Open in new window

    LVL 13

    Assisted Solution

    How about this

    $patharr = pathinfo(__FILE__);

    Echo $patharr['dirname'];

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now