代码之家  ›  专栏  ›  技术社区  ›  Gary Willoughby

如何使用PHP在本地网络上浏览目录?

  •  3
  • Gary Willoughby  · 技术社区  · 15 年前

    如何使用PHP列出Windows共享的内容?

    $SearchFolder = "\\\\192.168.1.100\\pdfoutput\\";
    
    if (is_dir($SearchFolder))
    {
        if ($Directory = opendir($SearchFolder))
        {
            while (($File = readdir($Directory)) !== false)
            {
                if(filetype($SearchFolder.$File) == "file")
                {
                    $this->Attachments[] = new Attachment($SearchFolder.$File);
                }
            }
            closedir($Directory);
        }
    }
    

    print(opendir($searchfolder));给出此错误:

    警告: openddir(\192.168.1.100\pdfoutput) [函数.opendir]:打开失败 目录:无错误 C:\users\gary\webserver\quickmail\maildetails.php 在线227

    这不符合预期。有什么想法吗?

    3 回复  |  直到 6 年前
        1
  •  3
  •   DisgruntledGoat    15 年前

    查看opendir函数的用户注释,网址为 http://uk3.php.net/function.opendir . 似乎有些信息可以帮助您。具体来说,戴夫兰登的这段代码可以解决您的问题:

    <?php
    // Define the parameters for the shell command
    $location = "\\servername\sharename";
    $user = "USERNAME";
    $pass = "PASSWORD";
    $letter = "Z";
    
    // Map the drive
    system("net use ".$letter.": \"".$location."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
    
    // Open the directory
    $dir = opendir($letter.":/an/example/path")
    ?>
    
        2
  •  1
  •   Gary Willoughby    15 年前

    我找到了一个很好的替代方法来使用本地网络路径,那就是使用FTP服务器。考虑到我也需要显示这个目录中的一些图像,这也很好。我使用的FTP服务器非常轻,允许从整个LAN访问此目录,而不会出现任何安全或权限错误。

    $SearchFolder = "ftp://192.168.0.104/PDFOutput/";
    
    if (is_dir($SearchFolder))
    {
        if ($Directory = opendir($SearchFolder))
        {
            while (($File = readdir($Directory)) !== false)
            {
                    if(filetype($SearchFolder.$File) == "file")
                    {
                            $this->Attachments[] = new Attachment($SearchFolder.$File);
                    }
            }
            closedir($Directory);
        }
    }
    
        3
  •  0
  •   JyothiKanth    6 年前

    下面的过程对我有用。 只需将共享位置映射到我们的系统。
    如果您有Windows 7:单击“开始”,然后单击“计算机”,再单击“映射网络驱动器”
    如果您有Windows 8:打开文件资源管理器,单击“计算机”选项卡,然后单击“映射网络驱动器”。通过提到共享驱动器/文件夹,我们可以直接访问内容。

    推荐文章