【问题标题】:How to make a function keep the original URL without defining it如何使函数保留原始 URL 而不定义它
【发布时间】:2016-08-24 18:08:15
【问题描述】:

我有两个文件。

file1.php

/gallery/file2.php

file1.php 有函数showUrl(); 打印当前的URL。 file2.php 包括 file1.php 如果函数在 file2.php 中执行,它将打印 file2.php

的目录

如何打印 file2.phpfile1.php 的 URL,该函数位于 file1.php 中而不定义它因为 URL 可以更改,无法定义?

【问题讨论】:

  • 你能举一个你文件中的使用例子吗? “url”是指“路径”?
  • 你不知道这个 url 因为你可以包含它吗?
  • 我得到了 file2.php 的路径,但我需要 file1.php 的路径
  • 换句话说,我希望我的函数保留来自 file1.php 的路径
  • 我知道,你已经说过了。但是,如果您有 file2 的路径并且您能够包含 file1,那么您应该能够将两者结合起来并创建 file1 的路径。你可以在这里找到类似问题的其他答案stackoverflow.com/questions/139794/…

标签: php function include


【解决方案1】:

试试这个:

file1.php

echo __FILE__;

file2.php

echo __FILE__;
include "../../file1.php" //or other path where your file1.php is located

【讨论】:

    猜你喜欢
    • 2017-08-02
    • 2015-07-27
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    相关资源
    最近更新 更多