【问题标题】:How to access images or files from the network drive in PHP如何在 PHP 中从网络驱动器访问图像或文件
【发布时间】:2018-02-15 10:55:34
【问题描述】:

我正在尝试从连接到我的机器的网络驱动器访问图像。 但我无法使用 php 访问它。我使用 net use 命令对其进行了映射,但我仍然无法访问它。请帮帮我。

 if($fh=opendir('\\\\F:')) {
 while (false !== ($fi =readdir($fh))) {
 echo "$fi\n";
 }
 }

即使我也尝试过下面的代码

   <?php
    $path = '\\Z:';

    $user = "administrator";
    $pass = "dev";
    $drive_letter = "Z";

    system("net use ".$drive_letter.": \"".$path."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
    $location = $drive_letter.":/";

    if ($handle = opendir($location)) {
       while (false !== ($entry = readdir($handle))) {
       echo "$entry"; echo "<br>";
       } 
       closedir($handle);
     }
     ?>        

【问题讨论】:

  • 那么你的错误日志是怎么说的?您使用什么 PHP 代码来访问驱动器?您是否有权访问该文件夹?
  • 是的,我已授予访问文件夹的权限。我没有收到任何错误日志。
  • 试试$file=fopen(file://F:/eventscript.txt', "r")
  • 试过了。不工作。

标签: php scandir network-drive opendir net-use


【解决方案1】:

我认为问题与运行 Apache 的用户有关,因为您的用户帐户上有一个带有凭据的映射驱动器,它与运行 Apache 的用户不同。

首先,让 Apache 以管理员身份运行,然后在脚本中运行 net use 命令:

<?php
$path = '\\\\younetworkdrive\\yoursharedfolder'; 

$user = "mickeymouse";
$pass = "waltdisney";
$drive_letter = "Z";

system("net use ".$drive_letter.": \"".$path."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
$location = $drive_letter.":/";

if ($handle = opendir($location)) {
    while (false !== ($entry = readdir($handle))) {
	echo "$entry";
    } 
    closedir($handle);
}

我刚试了一下....它的工作原理

【讨论】:

  • 不和我一起工作。请建议我哪里出错了?
  • 对不起,我的错误.... $path = '\\\\younetworkdrive\\yoursharedfolder';
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-14
  • 2017-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多