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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀