SimpleXML->asXML($filePath) 无法打开流权限被拒绝
我有一个更新 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的脚本无权写入
self::$_xmlFilePath
中的任何路径。如果不更多地了解您的环境,就很难提供更多建议。
它是 Windows 还是 Linux / Unix / Mac 文件系统?
PHP 运行在哪个用户下?
哪个用户拥有
self::$_xmlFilePath
以及该路径的权限是什么?更新
我认为考虑到这看起来只是本地开发,您最好的选择是使目标文件夹全局可写。您应该能够通过 Nautilus 或命令行执行此操作
请注意,这对于生产环境来说不是一个好的解决方案
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
Please note, this isn't a good solution for a production environment