如果目录或文件存在,如何获取url?

问题描述:

如果目录或文件存在,我需要获取url。 我的配置:如果目录或文件存在,如何获取url?

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .* ./user.php?action=$0 [QSA] 

我的PHP文件:

<?php 
    if (isset($_GET['action'])) { 
    echo $_GET['action']; 
    } 
    ?> 

请尝试用下面的代码: -

$path = 'path/to/file_or_dir'; 
if (file_exists($path)){ 

    $url = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://"; 
    $url .=$_SERVER["SERVER_NAME"]. dirname($path); 
    echo $url; 

}