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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
<?php
include('params.inc.php');
if(!empty($_POST['nom'])){
$erreurs = array(); //initialise un tableau d'erreurs au cas ou :)
$nom = mysql_escape_string(trim($_POST['nom'])); //enleve les espaces de chaque côté de la variable
$lienimage = '';
$typesacceptes = array('image/jpeg','image/jpg','image/png','image/gif');
//vérifie si les images existent et qu'elles sont au bon format
if(!empty($_FILES['image1']['name']) &&
!empty($_FILES['image2']['name']) &&
in_array($_FILES['image1']['type'],$typesacceptes) &&
in_array($_FILES['image2']['type'],$typesacceptes)
){
$lienimage = mysql_escape_string($_FILES['image1']['name']);
copy($_FILES['image1']['tmp_name'],'images/'.$lienimage);
copy($_FILES['image2']['tmp_name'],'images/miniatures/'.$lienimage);
//connexion à la BDD
$connect=mysql_connect(MYHOST,MYUSER,MYPASS) or die ('erreur de connexion');
mysql_select_db(MYDB) or die ('erreur de connexion à la base');
$requeteinsert = 'INSERT INTO images(nom,lienimage) VALUES(\''.$nom.'\',\''.$lienimage.'\')';
$result = mysql_query($requeteinsert,$connect);
echo '<p class="success">Votre image a bien été enregistrée!</p>';
mysql_close($connect);
}
else{
$erreurs[] = 'Veuillez uploader une image valide (format jpg, png ou gif)!';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Galerie Snoupix Flip | Admin</title>
<!-- CSS -->
<link rel="stylesheet" href="css/admin.css" type="text/css" media="screen, projection" />
</head>
<body>
<?php
if(!empty($erreurs)){
echo '<div class="error">
<p>Erreurs rencontrées</p>
<ul>';
foreach($erreurs as $erreur){
echo '<li>'.$erreur.'</li>';
}
echo '</ul>
</div>';
}
?>
<form method="post" action="admin.php" enctype="multipart/form-data">
<fieldset>
<legend>Ajout d'une image</legend>
<label for="nom">Nom</label>
<input type="text" id="nom" name="nom"/>
<label for="image1">Image</label>
<input type="file" id="image1" name="image1"/>
<label for="image2">Miniature</label>
<input type="file" id="image2" name="image2"/>
<button type="submit">Uploader</button>
</fieldset>
</form>
<table summary="Liste des images de la galerie">
<caption>Liste des images</caption>
<tr>
<th>Id</th>
<th>Nom</th>
<th>Supprimer</th>
</tr>
<?php
$connect=mysql_connect(MYHOST,MYUSER,MYPASS) or die ('erreur de connexion');
mysql_select_db(MYDB) or die ('erreur de connexion à la base');
if(!empty($_GET['sup']) && is_numeric($_GET['sup'])){
$requeteselect = 'SELECT lienimage FROM images WHERE id=\''.mysql_escape_string($_GET['sup']).'\'';
$result = mysql_query($requeteselect, $connect);
$image_courante = mysql_fetch_array($result,MYSQL_ASSOC);
unlink('images/'.$image_courante['lienimage']);
unlink('images/miniatures/'.$image_courante['lienimage']);
$requetesup = 'DELETE FROM images WHERE id=\''.mysql_escape_string($_GET['sup']).'\'';
$result = mysql_query($requetesup, $connect);
}
$requeteselect = 'SELECT id,lienimage,nom FROM images';
$result = mysql_query($requeteselect, $connect);
while($image_courante = mysql_fetch_array($result,MYSQL_ASSOC)){
echo '<tr>
<td>'.$image_courante['id'].'</td>
<td>'.stripslashes($image_courante['nom']).'</td>
<td><a href="admin.php?sup='.$image_courante['id'].'">Supprimer</a></td>
</tr>';
}
mysql_close($connect);
?>
</table>
</body>
</html> |
Partager