gpt4 book ai didi

php - 读取网络驱动器上的文件

转载 作者:可可西里 更新时间:2023-11-01 12:28:35 25 4
gpt4 key购买 nike

我在 Windows 服务器上运行 Xampp; Apache 使用本地帐户作为服务运行。在此服务器上,网络共享挂载为 X:,具有特定凭据。

我想访问位于 X: 的文件并运行以下代码

<?php
echo shell_exec("whoami");
fopen('X:\\text.txt',"r");
?>

得到

theservername\thelocaluser
Warning: fopen(X:\text.txt) [function.fopen]: failed to open stream: No such file or directory

我尝试运行 Apache,不是作为服务而是直接通过启动 httpd.exe 来运行 ...并且代码有效。

我看不出是什么导致了服务和应用程序之间的差异以及如何使其工作。

最佳答案

您不能使用驱动器盘符执行此操作,因为网络映射驱动器仅供单个用户使用,因此不能被服务使用(即使您要为该用户安装它)。

您可以直接使用 UNC 路径,例如:

fopen('\\\\server\\share\\text.txt', 'r');

但是请注意,PHP 对 UNC 路径的文件系统访问存在一些问题。一个例子是 bug I filed for imagettftext ,但 file_existsis_writeable 也存在问题。我没有报告后者,因为您可以从我长期 Unresolved imagettftext 错误中看出,这有什么意义。

关于php - 读取网络驱动器上的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14367687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com