how to grab the relative path of a file with php

前端 未结 2 1233
南旧
南旧 2021-01-26 18:44

i am trying to catch the relative path to a file to create a share link. From my httpdocs folder on the webserver, my file is here:

jack/single/uplo         


        
2条回答
  •  离开以前
    2021-01-26 19:21

    You could use preg_replace on the output of realpath to replace everything up to httpdocs with your site's URL:

    echo preg_replace('#^' . preg_quote($_SERVER['DOCUMENT_ROOT']) . '[\\\\/]#', "{$_SERVER['HTTP_HOST']}/", realpath('test6.php')) . "\n";
    

提交回复
热议问题