读取网络驱动器上的文件 [英] Read file on a network drive

查看:126
本文介绍了读取网络驱动器上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows Server上运行Xampp; Apache正在使用本地帐户作为服务运行. 在此服务器上,使用特定凭据将网络共享安装为X:.

I'm running Xampp on a Windows Server ; Apache is running as a service with a local account. On this server, a network share is mounted as X: with specific credentials.

我要访问X:上的文件并运行以下代码

I want to access files located on X: and run the following code

<?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

我尝试通过运行httpd.exe直接运行Apache,而不是将其作为服务运行... 代码就起作用了.

I tried to run Apache, not as a service but directly by launching httpd.exe ... and the code worked.

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

I can't see what causes the difference between the service and the application and how to make it works.

推荐答案

您无法使用驱动器号来完成此操作,因为网络映射的驱动器仅适用于单个用户,因此服务无法使用(即使您要为该用户安装它.

You're not able to do this using a drive letter, as network mapped drives are for a single user only and so can't be used by services (even if you were to mount it for that user).

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

What you can do instead is use the UNC path directly, for example:

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

但是,请注意,PHP对UNC路径的文件系统访问存在一些问题.一个示例是我为imagettftext提交的错误,但是file_existsis_writeable.我没有报告后者,因为正如您从我长期未解决的imagettftext错误中看到的那样,这有什么意义.

Note, however, that there are a few issues with PHP's filesystem access for UNC paths. One example is a bug I filed for imagettftext, but there are also issues with file_exists and is_writeable. I haven't reported the latter because as you can see from my long-outstanding bug with imagettftext, what's the point.

这篇关于读取网络驱动器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆