我有一個簡短的PHP程序,它加載一個XML文件(test02.xml),然後嘗試將它保存在另一個文件中。使用DOMDocument-> save('filename')保存xml文件時遇到困難
的程序是:
<?php
//The next three lines are needed to open a file for writing on the server I use.
$stream_options = array('ftp' => array('overwrite' => TRUE));
$stream_context = stream_context_create($stream_options);
$fxml = fopen("ftp://userid:[email protected]/public_html/programs/test03.xml","w",0,$stream_context);
//The next three lines create a new DOMDocument, load the input file, "test02.xml"
//and attempt to save the loaded file in the output file "test03.xml"
$doc = new DOMDocument;
$doc->load("test02.xml");
$doc->save("test03.xml");
?>
文件test03.xml正常打開,如果不存在則創建。但是,它沒有輸出。加載的文件test02.xml非空且格式良好的XML。我已經用其他PHP程序成功加載並讀取它。
當我運行上面的程序,我得到的消息:
警告:DOM文檔保存::(test03.xml)[domdocument.save]:未能打開流:權限被拒絕的/ home/yurow/
phpbuilder.com/manual/en/function.dom-domdocument-:wwwroot的/ yurowdesigns.com /方案/ xmlTest.php上線8
我已經在檢查了 '保存' 命令的語法save.php
它看起來是正確的。任何想法是什麼造成這個?
@ user1107199聽起來像/ home/yurow是使用ftp查看時的「/」根級別。所以,您可以簡單地在wwwroot目錄旁邊創建xmldata目錄。換句話說,查看/在你的ftp客戶端中,你會看到/ wwwroot和/ xmldata(以及你在其中的任何其他東西) – 2012-01-10 13:33:35
我創建了文件夾/ XMLFiles,併成功創建了文件test03.xml和fopen()聲明如下: $ fxml = fopen(「ftp:// userid:password!@ www.yurowdesigns.com/XMLFiles/test03.xml」,「w」,0,$ stream_context); (第10行)$ doc-> save(「/ home/yurow/XMLFiles/test03.xml」); 但是,上面的save()命令繼續產生警告消息:警告:DOMDocument :: save(/home/yurow/XMLFiles/test03.xml)[domdocument.save]:未能打開流:拒絕/ home中的權限/yurow/wwwroot/yurowdesigns.com/programs/xmlTest.php在第10行。它看起來像這個嬰兒被鎖定緊! – user1107199 2012-01-11 02:19:25
@ user1107199我不明白你爲什麼要通過ftp創建文件,然後在本地讀取它。假設你有這樣做的理由,你可以嘗試在腳本的頂部添加一個umask調用。例如的umask(0000)。和/或確保XMLFiles目錄已設置,以便您和Apache用戶可以讀取/寫入它。 – 2012-01-12 01:44:48