Ciao a tutti,
ho sviluppato in locale una pagina per generale un file XML.
Ecco qua il codice:
Codice PHP:
$filename = "../log_files/soldi/ricevuti/".$RICEVENTE.".xml";
// se non esiste il file per gli avvisi ne creo uno nuovo
if (!file_exists($filename)){
$handle = fopen($filename,"w");
$domxml = new DOMDocument("1.0");
$domxml->preserveWhiteSpace = false;
$domxml->formatOutput = true;
$root = $domxml->appendChild($domxml->createElement('holricevuti'));
$domxml->save($filename);
}
//in ogni caso aggiungo le nuove informazioni
$domxml = new DOMDocument("1.0");
$domxml->preserveWhiteSpace = false;
$domxml->formatOutput = true;
$domxml -> load($filename) or die("Impossibile aprire il file xml");
$root_list = $domxml->getElementsByTagName("holricevuti");
$root = $root_list -> item(0);
$transazione = $root->appendChild($domxml->createElement('transazione'));
$cessionario = $transazione->appendChild($domxml->createElement('cessionario'));
$cessionario->appendChild($domxml->createTextNode($_SESSION['utente']));
$data = $transazione->appendChild($domxml->createElement('data'));
$data->appendChild($domxml->createTextNode(strftime("%d/%m/%y")));
$ora = $transazione->appendChild($domxml->createElement('ora'));
$orad->appendChild($domxml->createTextNode(strftime("%H:%M:%S")));
$qta = $transazione->appendChild($domxml->createElement('quantita'));
$qta->appendChild($domxml->createTextNode($HOL_ADD));
$holcessionario = $transazione->appendChild($domxml->createElement('holcessionario'));
$holcessionario->appendChild($domxml->createTextNode($NEW_HOL_MITTENTE));
$holricevente = $transazione->appendChild($domxml->createElement('holricevente'));
$holricevente->appendChild($domxml->createTextNode($NEW_HOL_RICEVENTE));
$domxml->save($filename);
Tutto questo in locale funziona (cioé con PHP 5.3) mentre sul server di Aruba dà un sacco di problemi odiosi (PHP 4.4.9)
Ecco i vari problemi (tenete conto che $filename.... è SEMPRE LA RIGA 2):
se il mio codice è questo:
Codice PHP:
$filename = "tizio.xml";
// se non esiste il file per gli avvisi ne creo uno nuovo
if (!file_exists($filename)){
$domxml = new DOMDocument("1.0");
$domxml->preserveWhiteSpace = false;
$domxml->formatOutput = true;
$root = $domxml->appendChild($domxml->createElement('holricevuti'));
$root->appendChild($domxml->createTextNode("frwertwerw"));
$domxml->save($filename);
}
ottengo questo errore:
codice:
Warning: domdocument() [function.domdocument]: Start tag expected, '<' not found in /web/htdocs/www.phyrosia.com/home/provaxml.php on line 6
Fatal error: Call to undefined method: domdocument->appendchild() in /web/htdocs/www.phyrosia.com/home/provaxml.php on line 9
se invece è questo:
Codice PHP:
$filename = "tizio.xml";
// se non esiste il file per gli avvisi ne creo uno nuovo
if (!file_exists($filename)){
$domxml = new DOMDocument("<root/>");
//$domxml = new DOMDocument("1.0");
$domxml->preserveWhiteSpace = false;
$domxml->formatOutput = true;
$root = $domxml->appendChild($domxml->createElement('holricevuti'));
$root->appendChild($domxml->createTextNode("frwertwerw"));
$domxml->save($filename);
}
ottengo questo altro errore:
codice:
Fatal error: Call to undefined method: domdocument->appendchild() in /web/htdocs/www.phyrosia.com/home/provaxml.php on line 9
e gli dò anche ragione
se invece è questo:
Codice PHP:
$filename = "tizio.xml";
// se non esiste il file per gli avvisi ne creo uno nuovo
if (!file_exists($filename)){
$domxml = new DOMDocument("<?xml version=\"1.0\" encoding=\"utf-8\"?><root/>");
$domxml->preserveWhiteSpace = false;
$domxml->formatOutput = true;
$domxml->save($filename);
}
ottengo questo altro errore:
codice:
Fatal error: Call to undefined method: domdocument->save() in /web/htdocs/www.phyrosia.com/home/provaxml.php on line 11
Questo errore esce ognivolta non ci sono altri errori prima.
Ora mi chiedo due cose: perché???
e poi: come lo faccio funzionare?
spero qualcuno riuscirà ad aiutarmi, grazie in anticipo.
PS: ah, io vi ho fatto vedere solo gli errori relativi alla parte nell'if, ma questi ci sono anche dopo il caricamento del file tramite $doc->load("nomefile.ext");