从文件夹获取相对路径

时间:2014-08-03 17:12:28

标签: php relative-path absolute-path

我的filemanager文件夹位于:

localhost/cakeapp/app/webroot/js/tinymce/js/tinymce/plugins/filemanager/

在cakeapp根目录中,我有两个文件夹:

uploadedImages (cakeapp/uploadedImages)
UploadedImagesThumbs (cakeapp/uploadedImagesThumbs).

我在config.php档案中有这种情况:

$base_url ="http://localhost";

// path from base_url to base of upload folder (with start and final /)
$upload_dir = '/cakeapp/uploadedImages/';

// relative path from filemanager folder to thumbs folder (with final /)
$thumbs_base_path = '???????/uploadedImagesThumbs'; 

// relative path from filemanager folder to upload folder (with final /)
$current_path = '???????/uploadedImages/'; 

如何从filemanager文件夹中获取$thumbs_base_path$current_path的正确相对路径?

1 个答案:

答案 0 :(得分:0)

您可以尝试类似

的内容
function getRelativePath($from, $to) {
$patha = explode('/', $from);
$pathb = explode('/', $to);
$start_point = count(array_intersect($patha,$pathb));
while($start_point--) {
    array_shift($patha);
    array_shift($pathb);
}
$output = "";
if(($back_count = count($patha))) {
    while($back_count--) {
        $output .= "../";
    }
} else {
    $output .= './';
}
return $output . implode('/', $pathb);
}

检查source。还有更多示例

相关问题