php打开流失败的错误对一些用户,但不是其他用户


php Failed to open stream error for some users but not others

我一直在搜索关于此错误的StackExchange主题,但没有发现任何反映我正在经历的问题。

我目前的状态是,我有一个网页,其中包含一个可视化设置d3.js,其中一些对象是可点击的。单击其中一个后,将通过AJAX执行一个php脚本(根据所单击的对象传递变量),通过该脚本向MSSQL数据库运行查询,该数据库返回要通过FTP检索的图像列表。到目前为止,我知道这部分是工作的。

代码托管在运行IIS的win2008 r2服务器上。

在检索图像数组之后,执行一个循环,查看它们是否已经下载,如果没有,则在下面的循环中通过FTP获取图像:

        if(in_array($fileName,$files)) {
            //*** Look to see if the image has already been FTP'd
            $fileTo = "C:/inetpub/wwwroot/IRIS/images/" . $fileName;
        } else {
            $FTP_HOST = $wrow["serverId"] . ".prod.com";
            // *** Create the FTP object
            $ftpObj = new FTPClient();
            // *** Connect
            try{
                $ftpObj->connect($FTP_HOST,$FTP_USER,$FTP_PASS);
            } catch (PDOException $uc) {
                header('Content-type: application/json');
                echo json_encode("Error making the FTP connection");
                die();
            }
            $fileFrom = $wrow["fileSpec"];
            $fileTo = "C:/inetpub/wwwroot/IRIS/images/" . $fileName;
            try {
                $ftpObj->downloadFile($fileFrom,$fileTo);
            }catch (PDOException $uc) {
                header('Content-type: application/json');
                echo json_encode("Error transfering the file");
                die();
            }
        }

代码进入最后的try/catch循环,调用downloadFile所在的FTP类。注意,在建立连接时,所有用户使用相同的用户名和密码。

在ftp_class.php中,连接如下:
public function connect ($server, $ftpUser, $ftpPassword, $isPassive = false) {
    // *** Set up basic connection
    $this->connectionId = ftp_connect($server);
    // *** Login with username and password
    $loginResult = ftp_login($this->connectionId, $ftpUser, $ftpPassword);
    // *** Sets passive mode on/off (default off)
    ftp_pasv($this->connectionId, $isPassive);
    // *** Check connection
    if ((!$this->connectionId) || (!$loginResult)) {
        $this->logMessage('FTP connection has failed!',true);
        $this->logMessage('Attempted to connect to ' . $server . ' for user ' . $ftpUser, true);
        return false;
    } else {
        $this->logMessage('Connected to ' . $server . ', for user ' . $ftpUser);
        $this->loginOk = true;
        return true;
    }
}

和下载文件如下:

 public function downloadFile($fileFrom,$fileTo) {
    $asciiArray = array('txt','csv');
    $extension = end(explode('.',$fileFrom));
    if(in_array($extension,$asciiArray)) {
        $mode = FTP_ASCII;
    } else {
        $mode = FTP_BINARY;
    }
    if(ftp_get($this->connectionId,$fileTo,$fileFrom,$mode,0)) {
        $this->logMessage("file " . $fileTo . " successfully downloaded");
        return true;
    } else {
        $this->logMessage("There as an error downloading file " . $fileTo,true);
        return false;
    }
}

我通过Active Directory角色管理对我的应用程序的安全访问(这都是在公司内部网上),但是再次注意,ftp用户名和密码不依赖于这些角色。

这是我遇到的问题。如果任何服务器管理员尝试在我的服务器上获取、保存和显示,它都可以正常工作。如果一些用户(不是管理员)尝试执行相同的操作,则可以正常工作,但大多数用户无法完全执行。由于用户必须将文件写入映像文件夹(如上面的路径所示),因此我已将该文件夹设置为可共享给我需要访问的Active Directory角色,并为他们提供对该特定文件夹的读写权限。

返回错误:

警告: ftp_get(C:/inetpub/wwwroot/IRIS/images/041351W0006010251F00000064I04.jpg):打开流失败:Permission denied in C:'inetpub'wwwroot'dred'ftp_class.php on line 113

警告: ftp_get():打开C:/inetpub/wwwroot/IRIS/images/041351W0006010251F00000064I04.jpg在C:'inetpub'wwwroot'dred'ftp_class.php on line 113

第113行是ftp_get所在的行(见上文)。

我在故障排除中尝试了一些事情:

  1. 给Active Directory角色管理员写到我的服务器(不是我要保留的东西,只是试验):这工作
  2. 给Active Directory角色完全的读/写/更改访问服务器c驱动器(再次,只是测试),以及inetpub和wwwroot:不工作
  3. 设置ftp_pasv()为True:不工作

我想就是这样!如有任何建议,不胜感激。

经过几个小时的故障排除,我发现了这个问题。正如问题中提到的,目标是将图像FTP到我本地服务器上的图像文件夹中,以便它们可以嵌入到网页中。通过Windows文件资源管理器,我试图通过基于AD角色共享文件夹来提供对该文件夹的写访问。这还不够。

解决这个问题的方法是使用System Properties下的SECURITY选项卡,并为IIS_IUSRS提供对定义的映像文件夹的写访问。一旦设置好,FTP进程就可以将图像写入image文件夹。