SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru babyboy808's Avatar
    Join Date
    Nov 2004
    Location
    dublin
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Retrieve the filename of the current file????

    Hi,

    Does anybody know how to retrieve the filename of the current file I am working on?

    Thanks guys.

  2. #2
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Guru babyboy808's Avatar
    Join Date
    Nov 2004
    Location
    dublin
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect... Thanks UFTimmy

  4. #4
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always use this constant when I'm working on a project:
    Code:
    define("PAGE_NAME", basename(__FILE__));
    It will display a pagename without any query strings, etc.

    For example, the file example.php?var=1&var2=2 will become example.php

  5. #5
    SitePoint Guru babyboy808's Avatar
    Join Date
    Nov 2004
    Location
    dublin
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks for that snippet also maskd... Very useful.

  6. #6
    SitePoint Guru
    Join Date
    Jun 2002
    Posts
    616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, always use basename. A long time ago I had to deal with a site that referred to PHP_SELF throughout the code. When we had to change PHP to the CGI method for Apache/Windows it started adding php.exe or something to PHP_SELF - basename fixed that.

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    keep in mind the __FILE__ constant is quite different than PHP_SELF


    PHP_SELF is usually the filename which was(or possibly could be) used to access this via the url. this variable can be very different under different platforms and under different conditions.

    __FILE__ is always the name of the file which holds the code where the __FILE__ constant is located in.


    try this to see

    index.php
    PHP Code:
    echo 'im the index.php file<br>';
    echo 
    $_SERVER['PHP_SELF'];
    echo 
    '<br>';
    echo 
    __FILE__;
    echo 
    '<br><br>';
    include 
    'foo.php'
    foo.php
    PHP Code:
    echo 'im the foo.php file<br>';
    echo 
    $_SERVER['PHP_SELF'];
    echo 
    '<br>';
    echo 
    __FILE__;
    echo 
    '<br><br>';
    include 
    'foo.php'


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
  •