PHP:识别 Windows 上的连接点 (PHP5/Apache 2.4)

标签 php windows hyperlink junction

有什么方法可以识别文件夹是否是 Windows 系统上 PHP 中的连接点?甚至获取目标的路径/名称?

is_linkrealpath 不支持。

谢谢!

最佳答案

是的,通过使用lstat(),参见http://php.net/manual/de/function.lstat.php

它返回一个数组,其中包含有关文件名(目录/连接)的信息片段。您需要将键 mode 与某个位掩码进行比较。

mode 等于底层 OS 层中的 st_mode_stat 结构在 SYS\STAT.H 中定义。它包含一个字段 st_mode

关于st_mode 位掩码:

Bit mask for file-mode information. The _S_IFDIR bit is set if path specifies a directory; the _S_IFREG bit is set if path specifies an ordinary file or a device. User read/write bits are set according to the file's permission mode; user execute bits are set according to the filename extension.

     * #define  _S_IFDIR    0x4000
     * #define  _S_IFREG    0x8000

引自:https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2017


isJunction() 的 PHP 实现:https://github.com/composer/composer/blob/master/src/Composer/Util/Filesystem.php#L654-L678

警告 在对 Windows 进行最新更改后,这非常脆弱。参见 https://www.bountysource.com/issues/53997655-composer-update-is-deleting-pathed-windows-symlinked-local-repos-again-ref-4955

关于PHP:识别 Windows 上的连接点 (PHP5/Apache 2.4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31695209/

相关文章:

php - 突出PHP中两个字符串的区别

php - 处理数组的内容

windows - 如何访问位于 Windows 上具有保留系统名称(如 "CON")的文件夹中的本地文件?

java.lang.UnsatisfiedLinkError,我无法解决它

asp.net-mvc - 在 ASP.NET MVC 中生成链接?

Drupal - 对 mailto 链接使用 l 或 url 函数

php - 无法在 PHP shell_exec() 命令中运行 inkscape

php - 无法访问 HTML 中的输入 dom 变量

windows - ddev/docker 失败,出现 "Failed programming external connectivity",Windows 10

c# - 在 .msi 安装程序中包装 C# 应用程序