繁体   English   中英

从文件夹获取相对路径

[英]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);
}

检查源代码。它还有更多示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM