can i use php to know file name..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ggcdc
    New Member
    • Apr 2010
    • 8

    can i use php to know file name..?

    Hello,

    i want to ask can i use php to get a file name,

    for example, i uploaded two file called - abc.php, dfg.php on my server,

    once i go to the page - abc.php , something like a window or other will blow out and say : you are on abc.php page.

    then when i go to the page - dfg.php , as same, something like a window or other will blow out and say : you are on dfg.php page.

    so is there any php code can do this?

    Thanks
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    Have a look at $_SERVER['PHP_SELF'] and string basename ( string $path [, string $suffix ] )

    Comment

    • ggcdc
      New Member
      • Apr 2010
      • 8

      #3
      it's quite hard to read, please show me the one amoung those code...

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        Originally posted by ggcdc
        it's quite hard to read, please show me the one amoung those code...
        Knowing how to read manual is essential. Without it you are not getting very far. Anyhow here is the clue. Just do this:

        Code:
        echo $_SERVER['PHP_SELF'];

        Comment

        • ggcdc
          New Member
          • Apr 2010
          • 8

          #5
          with $_SERVER['PHP_SELF'] , will the result show only abc.php or /xxxx/adc.php or others?

          Comment

          • zorgi
            Recognized Expert Contributor
            • Mar 2008
            • 431

            #6
            So the clue didn't help!?

            Code:
            echo basename($_SERVER['PHP_SELF']);

            Comment

            • ggcdc
              New Member
              • Apr 2010
              • 8

              #7
              err.. just curious, because i got the result like { /abc.php}

              anyway, its work, thanks for your help.

              Comment

              • ggcdc
                New Member
                • Apr 2010
                • 8

                #8
                wrong board, post edited

                Comment

                • zorgi
                  Recognized Expert Contributor
                  • Mar 2008
                  • 431

                  #9
                  You should ask that question in JavaScript / Ajax / DHTML

                  Comment

                  • johny10151981
                    Top Contributor
                    • Jan 2010
                    • 1059

                    #10
                    hey,
                    Zorgi has answered your question. But even though you can try this to get your php file name :)

                    Code:
                    echo __FILE__;

                    Comment

                    Working...