doubei8168 2011-05-21 03:49
浏览 419

如何获取public_html文件夹的绝对路径?

$_SERVER['DOCUMENT_ROOT']

returns

/usr/local/apache/htdocs/

is there a way to get

/home/user/public_html/

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. 

And there is a folder

/home/user/public_html/images 

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

How do I get the path to the images folder without knowing where the test.php file will be?

  • 写回答

10条回答 默认 最新

  • doukao5073 2011-05-21 03:59
    关注

    Where is the file that you're running? If it is in your public html folder, you can do echo dirname(__FILE__);

    评论

报告相同问题?

悬赏问题

  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员