Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP未列出windows上的映射驱动器_Php_Windows_Shared Directory - Fatal编程技术网

PHP未列出windows上的映射驱动器

PHP未列出windows上的映射驱动器,php,windows,shared-directory,Php,Windows,Shared Directory,我正在尝试显示我的web服务器的所有固定、可移动和网络驱动器 PHP Version -> PHP 7.1.4 (cli) ( ZTS MSVC14 (Visual C++ 2015) x64 ) Apache Version -> Apache/2.4.26-dev (Win64) OS Version -> Windows 10 Pro x64 [Version 10.0.15063] PHP代码: /* Create a new file system o

我正在尝试显示我的web服务器的所有固定、可移动和网络驱动器

PHP Version    -> PHP 7.1.4 (cli) ( ZTS MSVC14 (Visual C++ 2015) x64 )
Apache Version -> Apache/2.4.26-dev (Win64)
OS Version     -> Windows 10 Pro x64 [Version 10.0.15063]
PHP代码:

/* Create a new file system object */
$FileSystemObject   =   new COM('Scripting.FileSystemObject');

/* Get system drives */
$Drives =   $FileSystemObject->Drives; 

/* Possible drive types */
$DriveTypes = array("Unknown","Removable","Fixed","Network","CD-ROM","RAM Disk"); 

$SystemDrives = [];

/* Loop through drives */
foreach($Drives as $Drive ){ 

    /* Get current drive options */
    $DriveOptions   =   $FileSystemObject->GetDrive($Drive); 

    /* If drive is removable, fixed or network */
    if (($DriveOptions->DriveType == 1)||($DriveOptions->DriveType == 2)||($DriveOptions->DriveType == 3)){

        $SystemDrives[] =   array(  "DriveType" =>  $DriveTypes[$DriveOptions->DriveType],
                                    "DrivePath" =>  $DriveOptions->Path,
                                    "DriveLabel"=>  $DriveOptions->VolumeName
                                );

    }   

}

/* Show drives */
print_r($SystemDrives);
答复:

    Array
(
    [0] => Array
        (
            [DriveType] => Fixed
            [DrivePath] => C:
            [DriveLabel] => 
        )

)

Apache作为系统运行。映射驱动器对系统具有完全权限。你知道我做错了什么吗?谢谢

无需调用
GetDrive
。事实上,我很惊讶它会返回任何有用的数据,这是字符串驱动器规范,而不是
$drive
对象。您需要的所有信息都已在
$Drives
中。删除行
$DriveOptions=$FileSystemObject->GetDrive($Drive)
,并将
$DriveOptions
的所有实例替换为
$Drive
。谢谢@ChrisR.Timmons。我相应地修改了我的代码,但响应保持不变。这可能是Apache的问题。尽管Apache是在系统帐户下运行的,但它们可能存在其他配置问题。要找到答案,请尝试在内置PHP web服务器下运行代码。运行
php-S localhost:8080-c。\php.ini
。(如果使用的是c:\windows\php.ini文件,则可以省略
-c
参数)。然后在浏览器中运行类似于
localhost:8080/index.php的页面。当我在Windows 8.1上使用内置服务器运行您的代码时,我可以看到所有映射的网络驱动器。@ChrisR.Timmons它与您的建议一起工作!一个小小的变化是,我使用了
C:\php\php.ini
而不是
\php.ini
,因为最初我收到了一个关于找不到COM类的错误。非常感谢你的帮助!现在呢?你知道apache有什么问题吗?这可能根本不是apache的问题。显然地关于如何绕过这一限制,人们进行了长时间的讨论。我个人的偏好是避免完全使用映射驱动器,而是使用。无需调用
GetDrive
。事实上,我很惊讶它会返回任何有用的数据,这是字符串驱动器规范,而不是
$drive
对象。您需要的所有信息都已在
$Drives
中。删除行
$DriveOptions=$FileSystemObject->GetDrive($Drive)
,并将
$DriveOptions
的所有实例替换为
$Drive
。谢谢@ChrisR.Timmons。我相应地修改了我的代码,但响应保持不变。这可能是Apache的问题。尽管Apache是在系统帐户下运行的,但它们可能存在其他配置问题。要找到答案,请尝试在内置PHP web服务器下运行代码。运行
php-S localhost:8080-c。\php.ini
。(如果使用的是c:\windows\php.ini文件,则可以省略
-c
参数)。然后在浏览器中运行类似于
localhost:8080/index.php的页面。当我在Windows 8.1上使用内置服务器运行您的代码时,我可以看到所有映射的网络驱动器。@ChrisR.Timmons它与您的建议一起工作!一个小小的变化是,我使用了
C:\php\php.ini
而不是
\php.ini
,因为最初我收到了一个关于找不到COM类的错误。非常感谢你的帮助!现在呢?你知道apache有什么问题吗?这可能根本不是apache的问题。显然地关于如何绕过这一限制,人们进行了长时间的讨论。我个人的偏好是避免完全使用映射驱动器,而是使用。