Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] XMLReader
Forum PHP.pl > Forum > Przedszkole
immortallch
  1. echo 'Current PHP version: ' . phpversion();
  2. ini_set('display_errors','1');
  3.  
  4. filesInDir('epg');
  5. function filesInDir($tdir)
  6. {
  7. $dirs = scandir($tdir);
  8. foreach($dirs as $file)
  9. {
  10. if (($file == '.')||($file == '..'))
  11. {
  12. }
  13. elseif (is_dir($tdir.'/'.$file))
  14. {
  15. filesInDir($tdir.'/'.$file);
  16. }
  17. else
  18. {
  19. czytaj($file);
  20. }
  21. }
  22. }
  23. function czytaj($file)
  24. {
  25.  
  26. $reader = new XMLReader();
  27. if (!$reader->open($file)) // nie ładuje kolejnego pliku ! dlaczego ?
  28. {
  29. echo "Nie otworzone " . $file. " <br>";
  30. }
  31. else
  32. {
  33. while ($reader->read())
  34. {
  35. if ($reader->nodeType)
  36. {
  37. if (XMLREADER::ELEMENT)
  38. {
  39. if ($reader->name == "title")
  40.  
  41. {
  42. $reader->read();
  43. echo $reader->value . "<br>";
  44. $title[] = trim($reader->value);
  45. }
  46. }
  47. }
  48. }
  49. if($reader->close())
  50. echo " Zamkniete <br>";
  51. unset($reader, $file);
  52. }
  53. }


XMLReader otwiera tylko pierwszy plik, nie chce otwierać kolejnych. Dlaczego? Z góry dziękuję za podpowiedź
erix
Coś w logach serwera/etc?
immortallch
Warning: XMLReader::open() [xmlreader.open]: Unable to open source data in /var/www/pomoc/epg2.php on line 35
Nie otworzone epg2.xml


Niestety nie mam więcej informacji

Wersja PHP: 5.3.3-7+squeeze13
erix
A co zwraca is_readable na ten plik?
immortallch
Dla pierwszego wczytanego pliku zwraca 1, dla kolejnych 0. Dlaczego nie można ich odczytywać? Pliki mają chmod 777, więc powinna być możliwość ich otwierania
erix
Na innym serwerze jest to samo?
immortallch
Nie mam możliwości sprawdzenia na innym serwerze sad.gif
erix
A maszyna wirtualna? tongue.gif
immortallch
  1. ini_set('display_errors','1');
  2. filesInDir('test');
  3. sprawdz('test/epg3.xml');
  4. czytaj('test/epg3.xml');
  5. sprawdz('test/epg1.xml');
  6. czytaj('test/epg1.xml');
  7. function sprawdz($file)
  8. {
  9. echo 'phpversion: ', phpversion(), "\n";
  10. echo $file, file_exists($file) ? ' exists' : ' does not exist', "\n";
  11. echo $file, is_readable($file) ? ' is readable' : ' is NOT readable', "\n";
  12. echo $file, is_writable($file) ? ' is writable' : ' is NOT writeable', "\n";
  13.  
  14. $fp = fopen($file, 'a+');
  15. if ( !$fp ) {
  16. echo 'last error: ';
  17. var_dump(error_get_last());
  18. }
  19. else {
  20. echo "ok.\n";
  21. }
  22. }
  23.  
  24. function filesInDir($tdir)
  25. {
  26. $dirs = scandir($tdir);
  27. print_r($dirs);
  28. echo "<br>";
  29. foreach($dirs as $file)
  30. {
  31.  
  32.  
  33. $rozszerzenie=explode(".", $file);
  34. if (($file == '.')||($file == '..'))
  35. {
  36. }
  37. else if ($rozszerzenie[1] == 'xml')
  38. {
  39. sprawdz($file);
  40. czytaj($file);
  41. }
  42.  
  43. }
  44. }
  45. function czytaj($file)
  46. {
  47. $reader = new XMLReader();
  48. if (!$reader->open($file)) // nie ładuje kolejnego pliku ! dlaczego ?
  49. {
  50. echo "Nie otworzone " . $file. " <br>";
  51. }
  52. else
  53. {
  54. while ($reader->read())
  55. {
  56. if ($reader->nodeType)
  57. {
  58. if (XMLREADER::ELEMENT)
  59. {
  60. if ($reader->name == "title")
  61. {
  62. if ($reader->read() != NULL)
  63. echo $reader->value ;
  64. $title[] = trim($reader->value);
  65. }
  66. }
  67. }
  68. }
  69. $reader->close();
  70. }
  71. }


W katalogu test mam 2 pliki: xml1.xml o chmod 644 i xml3.xml o chmod 777.
Po wywołaniu filesInDir funkcja sprawdz zwraca chmod 777 dla obu plików, a funkcja czytaj() ich nie czyta
Bez wywołania filesInDir i wpisaniu ręcznie lokalizacji pliku funkcja sprawdz zwraca odpowiednio chmod 644 i 777 (czyli prawidłowo), a funkcja czytaj() czyta oba pliki. Dlaczego ? Błędy poniżej


filesInDir:
  1. Array ( [0] => . [1] => .. [2] => epg1.xml [3] => epg3.xml )
  2. phpversion: 5.3.3-7+squeeze13 epg1.xml exists epg1.xml is readable epg1.xml is writable ok.
  3. Warning: XMLReader::read() [xmlreader.read]: /var/www/pomoc/epg/epg1.xml:1: parser error : Extra content at the end of the document in /var/www/pomoc/epg/epg2.php on line 88
  4.  
  5. Warning: XMLReader::read() [xmlreader.read]: in /var/www/pomoc/epg/epg2.php on line 88
  6.  
  7. Warning: XMLReader::read() [xmlreader.read]: ^ in /var/www/pomoc/epg/epg2.php on line 88
  8.  
  9. Warning: XMLReader::read() [xmlreader.read]: An Error Occured while reading in /var/www/pomoc/epg/epg2.php on line 88
  10. phpversion: 5.3.3-7+squeeze13 epg3.xml exists epg3.xml is readable epg3.xml is writable ok.
  11. Warning: XMLReader::read() [xmlreader.read]: /var/www/pomoc/epg/epg3.xml:1: parser error : Extra content at the end of the document in /var/www/pomoc/epg/epg2.php on line 88
  12.  
  13. Warning: XMLReader::read() [xmlreader.read]: in /var/www/pomoc/epg/epg2.php on line 88
  14.  
  15. Warning: XMLReader::read() [xmlreader.read]: ^ in /var/www/pomoc/epg/epg2.php on line 88
  16.  
  17. Warning: XMLReader::read() [xmlreader.read]: An Error Occured while reading in /var/www/pomoc/epg/epg2.php on line 88
  18.  


Bez filesInDir:
  1. phpversion: 5.3.3-7+squeeze13 test/epg3.xml exists test/epg3.xml is readable test/epg3.xml is writable ok.
  2.  
  3. tutaj odczytany tekst
  4.  
  5. phpversion: 5.3.3-7+squeeze13 test/epg1.xml exists test/epg1.xml is readable test/epg1.xml is NOT writeable
  6. Warning: fopen(test/epg1.xml) [function.fopen]: failed to open stream: Permission denied in /var/www/pomoc/epg/epg2.php on line 26
  7. last error: array(4) { ["type"]=> int(2) ["message"]=> string(108) "fopen(test/epg1.xml) [function.fopen]: failed to open stream: Permission denied" ["file"]=> string(27) "/var/www/pomoc/epg/epg2.php" ["line"]=> int(26) }
  8.  
  9. tutaj odczytany tekst
abort
Czytaj komunikaty o błędach. Ze zrozumieniem.
Masz jakiś błąd w pliku, który zacytowałeś. Problem jest taki, że błąd jest w linii 88, a zacytowałeś tylko 72 linie.
Chyba nie będziemy w stanie Ci pomóc smile.gif
immortallch
Mój błąd, skasowałem niepotrzebne funkcje, które są napisane, ale ich nie używam . Błąd jest w linii 55, nie w 88
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.