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");
?> |
Partager