<?php
$server = $_SERVER["SERVER_NAME"];
$pathpath = realpath("../../files/uploaded_file.jpg");
echo "You can link to the file using the following link... $server$pathpath";
?>
不幸的是,这会产生以下结果......
www.example.com/home/fhlinux123/g/example.com/user/htdocs/ninja/base/files/1.doc
而我所追求的如下......
www.example.com/files/uploaded_file.jpg
我无法假设文件夹'files'将始终位于同一目录中。
答案 0 :(得分:2)
这是因为realpath返回来自服务器盒根的绝对路径,而不是webserver htdocs root。 您可以从$ _SERVER [“DOCUMENT_ROOT”]中检索webserver htdocs root,然后从realpath返回的结果的开头删除它
快速而肮脏的例子:
$server = $_SERVER["SERVER_NAME"];
$pathpath = realpath("../../files/uploaded_file.jpg");
$serverPath = $_SERVER["DOCUMENT_ROOT"];
$pathpath = substr($pathpath,strlen($serverPath));
echo "You can link to the file using the following link... $server$pathpath";