[英]Eliminating Warning about simplexml_load_file PHP
I first scan directory tree and retrieve data from xml files with simplexml_load_file()
. 我首先扫描目录树,并使用simplexml_load_file()
从xml文件中检索数据。 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: 我在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);
Check if you can read the file first: 检查是否可以首先读取文件:
foreach ($items as $key=>$file){
if(is_readable($file) == false) {
echo "$file unreadable";
continue;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.