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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
| <!DOCTYPE html>
<html lang="en">
<head>
<title>Tilhet Prat</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<!-- Retro <IE9 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Materialize Kit CSS -->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css"media="screen,projection"/>
<!-- CSS -->
<link href="css/style.css" rel="stylesheet" />
</head>
<body>
<!-- Navbar on -->
<section class="navbar">
<div class="navbar-fixed">
<nav>
<div class="nav-wrapper">
<a href="index.html" class="brand-logo title center"><h4 class="show-on-medium-and-down hide-on-med-and-up">Administration</h4></li>
<a href="#" data-target="mobile" class="sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="hide-on-med-and-down brand-logo center">
<li><a href="index.html">Accueil du site</a></li>
<li class="title"><h3 class="hide-on-med-and-down">Administration</h3></li>
<li><a href="#">xxx</a></li>
</ul>
</div>
</nav>
</div>
<ul class="sidenav" id="mobile">
<li><a href="index.html">Accueil du site</a></li>
<li><a href="#">xxx</a></li>
</ul>
</section>
<!-- Navbar end -->
<?php
// on se connecte à la base de données
include 'bdd_co.php';
//Traitement du formulaire
if(isset($_POST["Valider"])) {
$nom = htmlspecialchars(trim($_POST["nom"]));
$valid = htmlspecialchars(trim($_POST["valid"]));
$datecrea = htmlspecialchars(trim($_POST["datecrea"]));
$description = htmlspecialchars(trim($_POST["description"]));
$alttxt = htmlspecialchars(trim($_POST["alttxt"]));
$extensions_valides = array( 'jpg' , 'jpeg' , 'gif' , 'png' );
$extension_upload = strtolower(substr(strrchr($_FILES['image']['name'],'.'),1));
$nomfinal = '../img/'.$nom.'_'.$datecrea.'.'.$extension_upload;
if(empty($nom)){
$alerte1 = true;
}
if(empty($valid)){
$alerte2 = true;
}
if(empty($datecrea)){
$alerte3 = true;
}
if(empty($alttxt)){
$alerte4 = true;
}
/*vérification de la taille du fichier*/
if ($_FILES['image']['size'] > $maxsize) {
$erreur5 = '<div><p style="color: #ff0000">Le fichier est trop gros</p></div>';
}
/*on vérifie l'extension du fichier*/
if (!in_array($extension_upload,$extensions_valides) ) {
$erreur6 = '<div><p style="color: #ff0000">Extension invalide (seul jpg, jpeg, gif, png sont autorisé)</p></div>';
}
if(empty($image)){
$alerte7 = true;
}
if (!$erreur1 && !$erreur2 && !$erreur3 && !$erreur4 && !$erreur5 && !$erreur6) {
//Si tout est ok
/*si la description est vide*/
if(empty($description)){
$description = NULL ;
}
// on enregistre les données
$result = $DBconnect->prepare('INSERT INTO IMAGES (nom,valid,datecrea,description,alttxt) VALUES (
:nom,
:valid,
:datecrea,
:description,
:alttxt
)');
$result->execute(array(
'nom' => $nom,
'valid' => $valid,
'datecrea' => $datecrea,
'description' => $description,
'alttxt' => $alttxt
));
// Termine le traitement de la requête
$result->closeCursor();
$resultat = move_uploaded_file($_FILES['image']['tmp_name'],$nomfinal);
//Si tout est ok, on informe le webmaster
if ($resultat){
$messimg_ok = '<div class="erreur alert alert-success"><b style="color: #008000">Image enregistrée avec succés!</b></div>';
}
$message_ok = '<div class="erreur alert alert-success"><b style="color: #008000">Informations enregistrée avec succés!</b></div>';
}
}
?>
<!-- Content on -->
<section class="content">
<div class="row container body">
<div class="col l12 s12 form">
<form method="post" action="ajout_image.php" enctype="multipart/form-data">
<h3 class="center col s12">Ajout d'image</h3>
<div class="input-field col s4">
<?php
if (!empty($_POST["nom"])) {
$contentnom = htmlspecialchars($_POST["nom"],ENT_QUOTES);
}
if(isset($alerte1)) {
echo '<input id="nom" name="nom" type="text" class="validate invalid" value="'.$contentnom.'"/>';
} else if ($contentnom) {
echo '<input id="nom" name="nom" type="text" class="validate valid" value="'.$contentnom.'"/>';
} else {
echo '<input id="nom" name="nom" type="text" class="validate" value="'.$contentnom.'"/>';
};
?>
<label for="nom">Nom</label>
<span class="helper-text" data-error="Vérifez le champ" data-success="Ok">Le nom de l'image, il doit être cour.</span>
</div>
<div class="input-field col s4">
<?php
if (!empty($_POST["valid"])) {
$contentvalid = htmlspecialchars($_POST["valid"],ENT_QUOTES);
}
if(isset($alerte2)) {
echo '<input id="valid" name="valid" type="text" class="validate invalid" value="'.$contentvalid.'"/>';
} else if ($contentvalid) {
echo '<input id="valid" name="valid" type="text" class="validate valid" value="'.$contentvalid.'"/>';
} else {
echo '<input id="valid" name="valid" type="text" class="validate" value="'.$contentvalid.'"/>';
};
?>
<label for="valid">Validité</label>
<span class="helper-text" data-error="Vérifez le champ" data-success="Ok">Si on affiche (1) ou non (2) l'image sur le site.</span>
</div>
<div class="input-field col s4">
<?php
if (!empty($_POST["datecrea"])) {
$contentdatecrea = htmlspecialchars($_POST["datecrea"],ENT_QUOTES);
}
if(isset($alerte3)) {
echo '<input id="datecrea" name="datecrea" type="text" class="datepicker validate invalid" value="'.$contentdatecrea.'"/>';
} else if ($contentdatecrea) {
echo '<input id="datecrea" name="datecrea" type="text" class="datepicker validate valid" value="'.$contentdatecrea.'"/>';
} else {
echo '<input id="datecrea" name="datecrea" type="text" class="datepicker validate" value="'.$contentdatecrea.'"/>';
};
?>
<label for="datecrea">Date de création</label>
<span class="helper-text" data-error="Vérifez le champ" data-success="Ok">La date d'ajout.</span>
</div>
<div class="input-field col s6">
<input id="description" name="description" type="text" class="validate" value="<?php if (!empty($_POST["description"])) { echo htmlspecialchars($_POST["description"],ENT_QUOTES); } ?>"/>
<label for="description">Description</label>
<span class="helper-text" data-error="Vérifez le champ" data-success="Ok">Une courte description de l'image, permet de mettre un texte sur l'image lorsque l'on clique dessus.<br/>Non obligatoire.</span>
</div>
<div class="input-field col s6">
<?php
if (!empty($_POST["alttxt"])) {
$contentalttxt = htmlspecialchars($_POST["alttxt"],ENT_QUOTES);
}
if(isset($alerte4)) {
echo '<input id="alttxt" name="alttxt" type="text" class="validate invalid" value="'.$contentalttxt.'"/>';
} else if ($contentalttxt) {
echo '<input id="alttxt" name="alttxt" type="text" class="validate valid" value="'.$contentalttxt.'"/>';
} else {
echo '<input id="alttxt" name="alttxt" type="text" class="validate" value="'.$contentalttxt.'"/>';
};
?>
<label for="alttxt">Texte alternatif</label>
<span class="helper-text" data-error="Vérifez le champ" data-success="Ok">Une courte trés description de "l'intérieur" de l'image, c'est pour les malvoyants.<br/>Exemple : Tableaux avec des poissons bleu répété horizontalement.</span>
</div>
<div class="col s12">
<div class="file-field input-field col s12">
<?php
if (!empty($_POST["image"])) {
$contentimg = htmlspecialchars($_POST["image"],ENT_QUOTES);
};
?>
<div class="btn">
<span>Fichier (500mo max)</span>
<input type="hidden" name="MAX_FILE_SIZE" value="524288000"/><!--500mo en octets-->
<input type="file" name="image" id="image">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" name="imagepath" id="imagepath"/>
<span class="helper-text" data-error="erreur" data-success="Ok"></span>
</div>
</div>
</div>
<div class="col s12 center">
<button class="btn waves-effect waves-light" type="submit" name="Valider">Envoyer
<i class="material-icons right">send</i>
</button>
<?php
if(isset($message_ok))
{
echo $message_ok;
}
if(isset($messimg_ok))
{
echo $messimg_ok;
}
?>
</div>
</form>
</div>
</div>
</section>
<!-- Content end -->
<!--Import Script js materialize-->
<script type="text/javascript" src="js/materialize.min.js"></script>
<script type="text/javascript" src="js/masonry.min.js"></script>
<script type="text/javascript" src="js/imagesloaded.min.js"></script>
<script type="text/javascript" src="js/init.js"></script>
</body>
</html> |
Partager