Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    [php] creare XML su server

    vorrei creare un file XML direttamente nella cartella del server con questo script (di prova)

    Codice PHP:
    $file= fopen("test.xml", "w"); 
    $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";  
    $_xml .="<root>\r\n";    
    $_xml .="\t<news>\r\n";  
    $_xml .="\t\t<data>" $gg."/".$mm."/".$aa "</data>\r\n"
    $_xml .="\t\t<testo_up>" $news "</testo_up>\r\n"$_xml .="\t\t<img>" $file "</img>\r\n"
    $_xml .="\t\t<testo_down>" $news1 "</testo_down>\r\n"$_xml .="\t</news>\r\n";    $_xml .="</root>";  
    fwrite($file$_xml);  
    fclose($file);
    questi sono gli errori


    Warning: fopen(test.xml) [function.fopen]: failed to open stream: Permission denied in D:\Inetpub\webs\thehardcrowscom\invia.php on line 46

    Warning: fwrite(): supplied argument is not a valid stream resource in D:\Inetpub\webs\thehardcrowscom\invia.php on line 66

    Warning: fclose(): supplied argument is not a valid stream resource in D:\Inetpub\webs\thehardcrowscom\invia.php on line 68


    PLS help me ci sto sbattendo la capocchia da un bel po

  2. #2
    usa la classe SimpleXML,
    ti faccio un esempio:

    codice:
    $str='<tagqualsiasi>il tuo codice xml</tagqualsiasi>';
    $xml=simplexml_load_string($str);
    $xml->asXML('percorso/del/fle/dasalvare.xml');
    per info:
    referenza ufficiale:
    www.php.net/simplexml
    o questa guidetta scritta da me:
    http://www.cyberfox.netsons.org/blog...p?a=view&id=13

  3. #3
    grazias te amo mucho

    ^^

    ora riprovo con le nozioni che mi hai dato e mi leggo la tua guida

    grazie ancora soprattutto per la velocita della risp


  4. #4
    nada ora mi danno questi errori

    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 9: parser error : Premature end of data in tag root line 2 in D:\Inetpub\webs\thehardcrowscom\invia.php on line 55

    Warning: simplexml_load_string() [function.simplexml-load-string]: in D:\Inetpub\webs\thehardcrowscom\invia.php on line 55

    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in D:\Inetpub\webs\thehardcrowscom\invia.php on line 55

    Fatal error: Call to a member function asXML() on a non-object in D:\Inetpub\webs\thehardcrowscom\invia.php on line 56

    Codice PHP:
    $str ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n"
    $str .="<root>\r\n";
     
    $str .="\t<news>\r\n"
    $str .="\t\t<data>" $gg."/".$mm."/".$aa "</data>\r\n"
    $str .="\t\t<testo_up>" $news "</testo_up>\r\n"
    $str .="\t\t<img>" $file "</img>\r\n"
    $str .="\t\t<testo_down>" $news1 "</testo_down>\r\n"
    $str .="\t</news>\r\n"
    $str .="</root>\r\n";  
    $xml=simplexml_load_string($str); 
    $xml->asXML('xml1\news.xml');

    sono disperatooooo purtroppo nn le ho mai fatte ste cose

  5. #5
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    è sufficente utilizzare w+ anzichè w per creare il file in automatico quando non esiste...

    Codice PHP:
    $file= fopen("test.xml", "w+");
    $_xml ="<?xml version="1.0\" encoding=\"UTF-8\" ?>\r\n";  
    $_xml .="<root>\r\n";    
    $_xml .="\t<news>\r\n";  
    $_xml .="\t\t<data>" $gg."/".$mm."/".$aa "</data>\r\n";
    $_xml .="\t\t<testo_up>" $news "</testo_up>\r\n"$_xml .="\t\t<img>" $file "</img>\r\n";
    $_xml .="\t\t<testo_down>" $news1 "</testo_down>\r\n"$_xml .="\t</news>\r\n";    $_xml .="</root>";  
    fwrite($file$_xml);  
    fclose($file);
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  6. #6
    Se sei su aruba e il percorso dove vuoi salvare il file NON è la cartella public scordatelo. L'unica cartella che puoi utilizzare per scrivere su quei server è appunto la cartella public.

  7. #7
    se usi simplexml togli tutti quei '\r\n' scrivi tutto insieme non servono spazi o 'a capo'

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.