从文件夹获取相对路径


Getting relative path from folder

我的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的正确相对路径?

你可以试试

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);
}

检查源。它有更多的例子