SimpleXML->asXML($filePath) 无法打开流权限被拒绝

发布于 2024-11-05 15:54:54 字数 2439 浏览 0 评论 0原文

我有一个更新 xml 文件的类,但是当保存文件时,我收到错误: SimpleXML->asXML($filePath) 无法打开流权限被拒绝。我以前从未遇到过这个问题,而且我在互联网上找不到太多有用的东西。

public static function CreateEntityConfig($database,$tables,$overwriteNodes = false) {
    if(!empty($database) && !empty($tables)) {
        $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        if(!$conn) { die('Could not connect: '.mysql_error()); }

        // check to see if database node exists and overwrite if $overwriteNodes set to true
        // else create new database node 
        mysql_select_db($database);
        if(self::NodeExists('database',array('name',$database))) {
            if($overwriteNodes) {
                self::RemoveNode('database', array('name',$database));
            } else {
                die($database.' node already exists');
            }
        } else {
            //echo '<br>type='.get_class(self::$_xml);
            $databaseNode = self::AddNode(self::$_xml, 'Database', array('name' => $database));
        }
        $tableNode = self::AddNode($databaseNode, 'Table', array('name' => $tables));

        $result = mysql_query('select * from '.$tables);
        if(!$result) { die('Query failed: '.  mysql_error()); }

        $i = 0;
        while($i < mysql_num_fields($result)) {
            $meta = mysql_fetch_field($result, $i);
            if($meta) {
                self::AddNode(
                    $tableNode,
                    'Field',
                    array(
                        'name' => $meta->name,
                        'not_null' => $meta->not_null,
                        'type' => $meta->type
                    )
                );
            } else {
                die('Unable to fetch meta information for '.$tables);
            }
            $i++;
        }
        mysql_free_result($result);
        //if(!self::$_xml->asXML()) { die('Unable save xml to file'); }
        echo self::$_xml->asXML(self::$_xmlFilePath);
    } else { die('Database and Table arguments required'); }
    mysql_close();
    echo self::$_xmlFilePath.' successfully built.';
}

尽管菲尔的答案并不完全正确,但它帮助我找到了适合我的解决方案。这是我所做的解释 - 看看第一个答案 https:// superuser.com/questions/19318/how-can-i-give-write-access-of-a-folder-to-all-users-in-linux

感谢您的所有帮助, 乙

I have a class that updates an xml file, however when it comes time to save the file I'm getting the error: SimpleXML->asXML($filePath) failed to open stream permission denied. I've never had this issue before and I can't find much of anything useful on the interwebs.

public static function CreateEntityConfig($database,$tables,$overwriteNodes = false) {
    if(!empty($database) && !empty($tables)) {
        $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        if(!$conn) { die('Could not connect: '.mysql_error()); }

        // check to see if database node exists and overwrite if $overwriteNodes set to true
        // else create new database node 
        mysql_select_db($database);
        if(self::NodeExists('database',array('name',$database))) {
            if($overwriteNodes) {
                self::RemoveNode('database', array('name',$database));
            } else {
                die($database.' node already exists');
            }
        } else {
            //echo '<br>type='.get_class(self::$_xml);
            $databaseNode = self::AddNode(self::$_xml, 'Database', array('name' => $database));
        }
        $tableNode = self::AddNode($databaseNode, 'Table', array('name' => $tables));

        $result = mysql_query('select * from '.$tables);
        if(!$result) { die('Query failed: '.  mysql_error()); }

        $i = 0;
        while($i < mysql_num_fields($result)) {
            $meta = mysql_fetch_field($result, $i);
            if($meta) {
                self::AddNode(
                    $tableNode,
                    'Field',
                    array(
                        'name' => $meta->name,
                        'not_null' => $meta->not_null,
                        'type' => $meta->type
                    )
                );
            } else {
                die('Unable to fetch meta information for '.$tables);
            }
            $i++;
        }
        mysql_free_result($result);
        //if(!self::$_xml->asXML()) { die('Unable save xml to file'); }
        echo self::$_xml->asXML(self::$_xmlFilePath);
    } else { die('Database and Table arguments required'); }
    mysql_close();
    echo self::$_xmlFilePath.' successfully built.';
}

Although Phil's answer was not exactly correct it helped me figure out the solution that worked for me. Here's an explanation of what I did - look at the first answer
https://superuser.com/questions/19318/how-can-i-give-write-access-of-a-folder-to-all-users-in-linux

thanks for any and all help,
B

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涫野音 2024-11-12 15:54:54

您的脚本无权写入 self::$_xmlFilePath 中的任何路径。

如果不更多地了解您的环境,就很难提供更多建议。

它是 Windows 还是 Linux / Unix / Mac 文件系统?

PHP 运行在哪个用户下?

哪个用户拥有 self::$_xmlFilePath 以及该路径的权限是什么?

更新

我认为考虑到这看起来只是本地开发,您最好的选择是使目标文件夹全局可写。您应该能够通过 Nautilus 或命令行执行此操作

chmod o+w /path/to/folder

请注意,这对于生产环境来说不是一个好的解决方案

Your script does not have permission to write to whatever path is in self::$_xmlFilePath.

Without knowing more about your environment, it's hard to offer more advice.

Is it a Windows or Linux / Unix / Mac filesystem?

Which user is PHP running under?

Which user owns self::$_xmlFilePath and what are the permissions on that path?

UPDATE

I think your best bet, considering this looks like local development only, would be to make the destination folder world writable. You should be able to do this via Nautilus, or command line

chmod o+w /path/to/folder

Please note, this isn't a good solution for a production environment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文