Php SimpleXML->;asXML($filePath)无法打开流权限被拒绝
我有一个更新xml文件的类,但是当需要保存文件时,我得到了一个错误:SimpleXML->asXML($filePath)无法打开流权限被拒绝。我以前从未遇到过这个问题,我在互联网上找不到什么有用的东西Php SimpleXML->;asXML($filePath)无法打开流权限被拒绝,php,simplexml,Php,Simplexml,我有一个更新xml文件的类,但是当需要保存文件时,我得到了一个错误:SimpleXML->asXML($filePath)无法打开流权限被拒绝。我以前从未遇到过这个问题,我在互联网上找不到什么有用的东西 public static function CreateEntityConfig($database,$tables,$overwriteNodes = false) { if(!empty($database) && !empty($tables)) {
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.';
}
public静态函数CreateEntityConfig($database、$tables、$overwriteNodes=false){
如果(!empty($database)&&!empty($tables)){
$conn=mysql\u connect(DB\u主机、DB\u用户、DB\u密码);
如果(!$conn){die('无法连接:'.mysql_error());}
//检查数据库节点是否存在,如果$overwriteNodes设置为true,则覆盖
//创建新的数据库节点
mysql\u select\u db($database);
if(self::NodeExists('database',array('name',$database))){
如果($overwriteNodes){
self::RemoveNode('database',array('name',$database));
}否则{
模具($database.'node已存在”);
}
}否则{
//echo“
type=”.get_类(self:$\uxml);
$databaseNode=self::AddNode(self::$_xml,'Database',array('name'=>$Database));
}
$tableNode=self::AddNode($databaseNode,'Table',array('name'=>$tables));
$result=mysql\u查询('select*from'.$tables);
如果(!$result){die('Query failed:'.mysql_error());}
$i=0;
而($i$meta->name,
'not_null'=>$meta->not_null,
'type'=>$meta->type
)
);
}否则{
die('无法获取“.$tables”的元信息);
}
$i++;
}
mysql_free_result($result);
//如果(!self::$_xml->asXML()){die('cannotable save xml to file');}
echo self:$\u xml->asXML(self:$\u xmlFilePath);
}else{die('Database and Table arguments required');}
mysql_close();
echo self::$\u xmlFilePath。“已成功生成”;
}
虽然菲尔的回答并不完全正确,但它帮助我找到了适合我的解决方案。下面是我所做的解释——看看第一个答案
谢谢你的帮助,
B您的脚本无权写入
self::$\u xmlFilePath
中的任何路径
如果不了解你的环境,就很难提供更多的建议
它是Windows还是Linux/Unix/Mac文件系统
PHP在哪个用户下运行
哪个用户拥有self::$\u xmlFilePath
以及该路径上的权限是什么
更新
考虑到这看起来只是本地开发,我认为您最好的选择是使目标文件夹世界可写。您应该能够通过Nautilus或命令行执行此操作
chmod o+w /path/to/folder
请注意,对于生产环境来说,这不是一个好的解决方案我运行的是ubuntu 11,它运行的用户对该目录具有写访问权限,否则我将无法创建该项目。脚本是否可能在其他用户下执行?我的系统中只有我和root@bflemi3您是通过命令行运行它还是浏览web服务器上的脚本?此外,我认为您会发现,用户远远不止两个;-)@Phil通过浏览器浏览脚本。哦,我不知道——我对ubuntu和linux基本上是新手。Thanks@bflemi3我认为默认的Ubuntu Apache用户是
www-data
。请参阅我的最新答案,并检查.htaccess是否允许访问特定目录。请记住,启用基本身份验证使得访问文件夹有时会产生此类问题。