问题描述
$_SERVER['DOCUMENT_ROOT']
返回
/usr/local/apache/htdocs/
有没有办法
/home/user/public_html/
问题是我必须编写一个脚本,该脚本可以位于public_html文件夹或public_html文件夹的子文件夹中.该脚本应将上传的文件保存到public_html目录(例如图片)内的文件夹中.换句话说,让我们说我的文件是test.php,它的路径是
The problem is that I have to write a script which can be in the public_html folder or a sub-folder of the public_html folder. The script should save uploaded files into a folder inside public_html directory(say images). In other words let us say that my file is test.php and the path to it is
/home/user/public_html/test/test.php.
有一个文件夹
/home/user/public_html/images
必须保存通过test.php上传的文件.我不知道将在哪里运行test.php文件.例如,它可以位于路径
where files uploaded via test.php have to be saved. I don't know where the test.php file will be run. For example it can be at the path
/home/user/public_html/test/another-dir/test.php
如何在不知道test.php文件在哪里的情况下获取images文件夹的路径?
How do I get the path to the images folder without knowing where the test.php file will be?
推荐答案
在阅读了此问题并继续在我的googlesurf上找到的东西:
something I found today, after reading this question and continuing on my googlesurf:
https://docs.joomla.org/How_to_find_your_absolute_path
<?php
$path = getcwd();
echo "This Is Your Absolute Path: ";
echo $path;
?>
为我工作
这篇关于如何获取public_html文件夹的绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!