解析符号链接和相对URL

时间:2015-10-03 15:00:11

标签: php symlink

我有一个符号链接/var/www/html/lib/,指向/var/www/application/lib/

在文件/var/www/application/lib/testing/imageMaker2/otherFile.php中,我创建了一个新文件/var/www/application/lib/testing/imageMaker2/images/test.png

接下来,我希望otherFile.php将相对于网络服务器文档根目录的URL发送给客户端(即/lib/testing/imageMaker2/images/test.png)。

如果没有先前的符号链接知识,这怎么可能?

test.php的

<?php
require_once('otherFile.php');
otherFile(__DIR__.'/images/'); //Or what ever upload directory is desired.
?

otherFile.php

<?php
function otherFile($path) {
    $path_parts = pathinfo($_SERVER['PHP_SELF']);
    $image='test.png';
    echo('$path                               => '.$path."\n");
    echo('$image                              => '.$image."\n");
    echo('$path/$image                        => '.$path.'/'.$image."\n");
    echo('__DIR__                             => '.__DIR__."\n");
    echo('__FILE__                            => '.__FILE__."\n");
    echo('$_SERVER[SCRIPT_FILENAME]           => '.$_SERVER['SCRIPT_FILENAME']."\n");
    echo('realpath($_SERVER[SCRIPT_FILENAME]) => '.realpath($_SERVER['SCRIPT_FILENAME'])."\n");
    echo('$_SERVER[PHP_SELF]                  => '.$_SERVER['PHP_SELF']."\n");
    echo('$_SERVER[DOCUMENT_ROOT]             => '.$_SERVER['DOCUMENT_ROOT']."\n");
    echo('$path_parts[dirname]                => '.$path_parts['dirname']."\n");
    echo('dirname($_SERVER[PHP_SELF])         => '.dirname($_SERVER['PHP_SELF'])."\n");
}
?>

输出

$path                               => /var/www/application/lib/testing/imageMaker2/images/
$image                              => test.png
$path/$image                        => /var/www/application/lib/testing/imageMaker2/images//test.png
__DIR__                             => /var/www/application/lib/testing/imageMaker2
__FILE__                            => /var/www/application/lib/testing/imageMaker2/otherFile.php
$_SERVER[SCRIPT_FILENAME]           => /var/www/html/lib/testing/imageMaker2/test.php
realpath($_SERVER[SCRIPT_FILENAME]) => /var/www/application/lib/testing/imageMaker2/test.php
$_SERVER[PHP_SELF]                  => /lib/testing/imageMaker2/test.php
$_SERVER[DOCUMENT_ROOT]             => /var/www/html
$path_parts[dirname]                => /lib/testing/imageMaker2
dirname($_SERVER[PHP_SELF])         => /lib/testing/imageMaker2

1 个答案:

答案 0 :(得分:0)

根据你的意见......

<td>

然后你只需要提取你想要的东西。