0

我首先扫描目录树并使用 .xml 从 xml 文件中检索数据simplexml_load_file()。该功能正常工作,但我收到警告:

Warning: simplexml_load_file(startfolder/cyrilic) [function.simplexml-load-file]: failed to open stream: Permission denied in C:\xampp\htdocs\begin\xxx.php on line 36

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "startfolder/cyrilic" in C:\xampp\htdocs\begin\xxx.php on line 36  

当有更改的子文件夹时,会出现此警告。我在 php.ini 中设置:

allow_url_fopen = On
allow_url_include = On

代码是:

$dir    = 'startfolder';
        $items = glob($dir . '/*');
        $table = 'book';
         for ($i = 0; $i < count($items); $i++) {
             if (is_dir($items[$i])) {
                 $add = glob($items[$i] . '/*');
                 $items = array_merge($items, $add);
             }
         }
        echo "<ul id='booklist'>"."</n>";
        foreach ($items as $key=>$file){
            $url = $file;
            $xml = simplexml_load_file($url);  
            $book_count = count($xml->book); 
4

1 回答 1

1

检查您是否可以先读取文件:

foreach ($items as $key=>$file){
    if(is_readable($file) == false) {
        echo "$file unreadable";
        continue;
    }
于 2013-08-15T11:24:28.667 回答