开发者

SimpleXML->asXML($filePath) failed to open stream permission denied

开发者 https://www.devze.com 2023-03-04 17:13 出处:网络
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 i

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))) {
            开发者_JS百科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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号