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 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿