Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    131
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Displaying filename w/ dir info (resolved)

    Is it possible to display purely the filename of the file which is currently on screen?

    "__FILE__" does more than i'd care for it to do, I dont need to know the masses of directories before it, just *.php would be wonderfull!


    Is it possible to have a value and deduct specific text from it?

    Could i do something like
    PHP Code:
    $fullfilename __FILE__ // (/home/username/public_html/domain/filename.php)

    $shortfilename $fullfilename "/home/username/public_html/domain/"
    I know the above wont work, but thats effectively what i want (clearly i should start my own programming language!! ) but ive no idea if something like that is out there?

    Basically im desperate just to have the filename alone, any care to put me out of my misery?

    Cheers,
    PaulC2K
    Last edited by PaulC2K; 02-11-2006 at 11:59 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    See basename()

    dumpfi

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    basename($_SERVER['PHP_SELF'])
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'll just might add that $_SERVER['PHP_SELF'] and __FILE__ work a bit different.
    PHP Code:
    // index.php
    <?php
    print 'basename(__FILE__): ' basename(__FILE__) . "<br />\n";
    print 
    'basename($_SERVER[\'PHP_SELF\']): ' basename($_SERVER['PHP_SELF']) . "<br />\n";
    print 
    'Now for include.php' "<br />\n";
    include 
    'include.php';
    ?>
    // include.php
    <?php
    print 'basename(__FILE__): ' basename(__FILE__) . "<br />\n";
    print 
    'basename($_SERVER[\'PHP_SELF\']): ' basename($_SERVER['PHP_SELF']) . "<br />\n";
    ?>
    The result of that would be:
    Code:
    basename(__FILE__): index.php
    basename($_SERVER['PHP_SELF']): index.php
    Now for include.php
    basename(__FILE__): include.php
    basename($_SERVER['PHP_SELF']): index.php
    __FILE__ holds the file which is being currently parsed and $_SERVER['PHP_SELF'] holds always the first php file.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #5
    Regular Coder
    Join Date
    Jul 2005
    Posts
    131
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Thumbs up

    Guys, your superstars!!
    Had a rumage round php.net using 'file' and 'filename' to see if that brought any luck, figured there must be a straight forward way to get the result i needed but '__FILE__' didnt point me in the direction of 'basename' and i knew i could count on you guys

    Thanks for the help

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you're welcome!

    interesting addition from marek_mar --> i only use '__FILE__' for debugging and errorreporting purposes. For selfreferencing functionalitys (like forms that post to themselves or to prevent direct requests to include-files), i always use $_SERVER['PHP_SELF']
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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