filesInDir('test');
sprawdz('test/epg3.xml');
czytaj('test/epg3.xml');
sprawdz('test/epg1.xml');
czytaj('test/epg1.xml');
function sprawdz($file)
{
echo $file, is_readable($file) ?
' is readable' : ' is NOT readable', "\n"; echo $file, is_writable($file) ?
' is writable' : ' is NOT writeable', "\n";
$fp = fopen($file, 'a+'); if ( !$fp ) {
}
else {
}
}
function filesInDir($tdir)
{
$dirs = scandir($tdir);
foreach($dirs as $file)
{
if (($file == '.')||($file == '..'))
{
}
else if ($rozszerzenie[1] == 'xml')
{
sprawdz($file);
czytaj($file);
}
}
}
function czytaj($file)
{
$reader = new XMLReader();
if (!$reader->open($file)) // nie ładuje kolejnego pliku ! dlaczego ?
{
echo "Nie otworzone " . $file. " <br>"; }
else
{
while ($reader->read())
{
if ($reader->nodeType)
{
if (XMLREADER::ELEMENT)
{
if ($reader->name == "title")
{
if ($reader->read() != NULL)
$title[] = trim($reader->value); }
}
}
}
$reader->close();
}
}
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:
Array ( [0] => . [1] => .. [2] => epg1.xml [3] => epg3.xml )
phpversion: 5.3.3-7+squeeze13 epg1.xml exists epg1.xml is readable epg1.xml is writable ok.
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
Warning: XMLReader::read() [xmlreader.read]: in /var/www/pomoc/epg/epg2.php on line 88
Warning: XMLReader::read() [xmlreader.read]: ^ in /var/www/pomoc/epg/epg2.php on line 88
Warning: XMLReader::read() [xmlreader.read]: An Error Occured while reading in /var/www/pomoc/epg/epg2.php on line 88
phpversion: 5.3.3-7+squeeze13 epg3.xml exists epg3.xml is readable epg3.xml is writable ok.
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
Warning: XMLReader::read() [xmlreader.read]: in /var/www/pomoc/epg/epg2.php on line 88
Warning: XMLReader::read() [xmlreader.read]: ^ in /var/www/pomoc/epg/epg2.php on line 88
Warning: XMLReader::read() [xmlreader.read]: An Error Occured while reading in /var/www/pomoc/epg/epg2.php on line 88
Bez filesInDir:
phpversion: 5.3.3-7+squeeze13 test/epg3.xml exists test/epg3.xml is readable test/epg3.xml is writable ok.
tutaj odczytany tekst
phpversion: 5.3.3-7+squeeze13 test/epg1.xml exists test/epg1.xml is readable test/epg1.xml is NOT writeable
Warning: fopen(test/epg1.xml) [function.fopen]: failed to open stream: Permission denied in /var/www/pomoc/epg/epg2.php on line 26
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) }
tutaj odczytany tekst