voila mon script
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
<?php
$dossier = '../images/';
$rep_mini = "../images/mini/";
$fileName="legende.xml"; 
// création du nouvel objet document
$dom = new DomDocument();
// chargement à partir du fichier
$dom->load($dossier . $fileName);
 
if (isset($_POST['modifier'])){
  if ($_POST['commentaire']!=""){
  $exist=false;
  echo $_POST['photo']. " modifier";
  $listeCom = $dom->getElementsByTagName("commentaire");
  foreach($listeCom as $com)
  { 
    if ($com->getAttribute("id")== $_POST['photo']) {
    $exist=true;
    $com->firstChild->nodeValue = $_POST['commentaire'];
    $dom->save($dossier . $fileName);
    }
  }
 
  if(!$exist){
    $nouveauCom = $dom->createElement("commentaire");
    $nomCom = $dom->createTextNode($_POST['commentaire']);
    $nouveauCom->setAttribute("id", $_POST['photo'] );
    $nouveauCom->appendChild($nomCom);
    $commentaires = $dom->documentElement;
    $commentaires->appendChild($nouveauCom);
    $dom->appendChild($commentaires);
    $dom->save($dossier . $fileName);
  }
  }
  else
  {
    $listeCom = $dom->getElementsByTagName("commentaire");
    foreach($listeCom as $com)
    { 
      if ($com->getAttribute("id")== $_POST['photo'])
      {
        $dom->documentElement->removeChild($com);
        $dom->save($dossier . $fileName);
      }
    }
  }
 } 
 include("index.php5");
?>
ce scripte permet de modifier le nœud commentaire du fichier XML "legende.xml". je pensais qu'il fonctionnait mais j'ai essayé avec un commentaire plus long. et au moment de la sauvegarde ça plante et du coup mon fichier se vide.