You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

<?php
$url = $_POST['urlField'];
$popup = $_POST['popupField'];
$img = $_FILES['imgField'];
$title = $_POST['titreField'];
// Préparation de l'image2
$content_dir = 'images/links/'; // dossier où sera déplacé le fichier
$tmp_file = $img['tmp_name']; // Fichier temporaire
// Vérification de l'upload
if( !is_uploaded_file($tmp_file) )
{
exit("Le fichier est introuvable");
}
// on vérifie maintenant l'extension
$type_file = $img['type'];
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'png') && !strstr($type_file, 'gif') )
{
exit("Le fichier n'est pas une image");
}
// on copie le fichier dans le dossier de destination
$name_file = $img['name'];
if( preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $name_file) )
{
exit("Nom de fichier non valide");
}
else if( !move_uploaded_file($tmp_file, $content_dir . $name_file) )
{
exit("Impossible de copier le fichier dans $content_dir");
}
$doc = new DOMDocument;
$doc->load('db/links.xml');
$xpath = new DOMXpath($doc);
// Creating new node
$newNode = $doc->createElement('link');
$newURL = $doc->createElement('url', $url);
if($popup == '1')
$newClick = $doc->createElement('onclick', 'popup');
else
$newClick = $doc->createElement('onclick', '');
$newImg = $doc->createElement('img', $name_file);
$newTitle = $doc->createElement('title', $title);
$newNode->appendChild($newURL);
$newNode->appendChild($newClick);
$newNode->appendChild($newImg);
$newNode->appendChild($newTitle);
$searchLabel = $xpath->query('reserve');
$searchLabel->item(0)->appendChild($newNode);
$doc->save('db/links.xml');