dtby67541 2013-08-15 10:59
浏览 49
已采纳

消除有关simplexml_load_file PHP的警告

I first scan directory tree and retrieve data from xml files with simplexml_load_file(). The function work correctly, but I receive warning:

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  

This warning appears, when there have changing subfolder. I set in php.ini:

allow_url_fopen = On
allow_url_include = On

The code is:

$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); 
  • 写回答

1条回答 默认 最新

  • douwen4401 2013-08-15 11:24
    关注

    Check if you can read the file first:

    foreach ($items as $key=>$file){
        if(is_readable($file) == false) {
            echo "$file unreadable";
            continue;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制