PHP: Get absolute path from absolute URL

前端 未结 4 1630
闹比i
闹比i 2020-12-10 06:43

I have an absolute path of a file, Is there a way to get the file absolute path

http://domainname/rootfolder/filename.php

and I wanna get s

4条回答
  •  -上瘾入骨i
    2020-12-10 07:18

    Try $_SERVER['DOCUMENT_ROOT']. Assuming a URL like

    http://example.com/subfolder/somefile.html
    

    and the file's actual location on the server being

    /home/sites/example.com/html/subfolder/somefile.html
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--- $_SERVER['DOCUMENT_ROOT']
    

提交回复
热议问题