【发布时间】:2016-02-27 16:08:58
【问题描述】:
在 PHP 中有一种方法可以运行脚本来检索执行 scipt 的文件夹中每个文件的完整 URL? 谢谢
【问题讨论】:
-
@Dagon 1= ?而不是 =?
标签: php
在 PHP 中有一种方法可以运行脚本来检索执行 scipt 的文件夹中每个文件的完整 URL? 谢谢
【问题讨论】:
标签: php
获取 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
【讨论】:
您可以使用迭代器遍历目录。然后使用 pathinfo() 获取文件的完整路径。
【讨论】: