【问题标题】:PHP for get full url of all files within the folder where is it executed? [closed]PHP用于获取执行文件夹中所有文件的完整URL? [关闭]
【发布时间】:2016-02-27 16:08:58
【问题描述】:

在 PHP 中有一种方法可以运行脚本来检索执行 scipt 的文件夹中每个文件的完整 URL? 谢谢

【问题讨论】:

标签: php


【解决方案1】:

获取 URL 并不容易。 PHP 并不总是以与 URL 相关的路径方式工作。您的环境可能已设置为 path=URL,也可能已设置为将所有请求发送到一个 PHP 控制器,然后由该控制器计算结果。

然而,要找到路径非常简单。

$directory = __DIR__; //Gets the current directory path
$contents = scandir($directory); //Get all files and folders from the $directory
$contents = array_diff($contents, array('..', '.')); //If a linux environment, this removes the ".." and "." occurences

Scandir documentation.

【讨论】:

    【解决方案2】:

    您可以使用迭代器遍历目录。然后使用 pathinfo() 获取文件的完整路径。

    【讨论】:

      猜你喜欢
      • 2015-06-15
      • 1970-01-01
      • 2011-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 1970-01-01
      • 2016-01-31
      相关资源
      最近更新 更多