How do I get the file name through an include?

Discussion in 'PHP' started by Imozeb, Apr 19, 2010.

  1. #1
    I have an include that leads to another include. Like:

    PHP code:
    
    //file 1
    include(../../file2.php);
    //file 2
    include(../../folder/folder2/file3.php);
    //file 3
    $filename = ??? file name of file 1?
    
    Code (markup):
    How would I get the file name of file 1 using PHP in file 3?

    Thanks!

    ~imozeb :)
     
    Imozeb, Apr 19, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    If I understood you correctly, you can get the file name writing $filename after including the file.
     
    s_ruben, Apr 19, 2010 IP
  3. trickyshaun

    trickyshaun Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    basename(__FILE__) to get current file name !
     
    trickyshaun, Apr 20, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    <?php
    
    //file 1
    include('../../file2.php');
    //file 2
    include('../../folder/folder2/file3.php');
    //file 3
    
    $inc = get_included_files();
    
    $filename = basename($inc[1]);
    ?>
    PHP:
     
    danx10, Apr 20, 2010 IP