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
|
<?php
include ('connection.php');
include ('index.php');
$req = ("SELECT NomRubrique FROM rubri order by NomRubrique asc");
$result = mysql_query($req);
?>
<select name="choix">
<?php
while ($donnees = mysql_fetch_array($result))
{
echo "<option value = '$donnees[NumeroRubrique]'>" .$donnees['NomRubrique'] . "</option>";
}
$test = $_POST['choix'];
?>
</select>
<?php
//echo'<form action="ajout-image.php" method="post">
// <input name="txt_nom" type="text" value="'.$test.'">
//</form>';
//$nomrubrique=$_POST['txt_nom'];
?>
<form enctype="multipart/form-data" action="ajout-image.php" method="post">
Chemin de l'image : <input name="fichier" type="file" /><br /><br />
Titre de l'image : <input name="titre" type="text" size="20" /><br /><br />
Commentaire de l'image : <textarea name="commentaire_photo" cols="20" rows="7">
</textarea><br /><br />
<input name="txt_nom" type="text" value="<?php echo $test; ?>" />
<input name="ajout" type="hidden" value="3">
<input type="submit" value="Ajouter l'image" />
</form>
<?php
$test = $_POST['txt_nom'];
if ($_POST['ajout'] == 3)
{
$titre_photo=$_POST['titre'];
$commentaire_photo=$_POST['commentaire_photo'];
$nom_rubr=$test;
$req=mysql_query("SELECT NumeroRubrique FROM rubri WHERE NomRubrique='".$nom_rubr."';");
//$num_ope=mysql_result($req, 0);
while ($ligne = mysql_fetch_array($req) )
$num_rubr=$ligne[0];
$target = 'photos/reduites/'; // Repertoire cible
$extensions = 'jpg'; // Extension du fichier sans le .
$max_size = 100000; // Taille max en octets du fichier
$width_max = 300; // Largeur max de l'image en pixels
$height_max = 300; // Hauteur max de l'image en pixels
//---------------------------------------------
// DEFINITION DES VARIABLES LIEES AU FICHIER
//---------------------------------------------
$nom_file = $_FILES['fichier']['name'];
$taille = $_FILES['fichier']['size'];
$tmp = $_FILES['fichier']['tmp_name'];
//----------------------
// SCRIPT D'UPLOAD
//----------------------
if(!empty($_FILES['fichier']['name']))
{
// On vérifie l'extension du fichier
if(substr($nom_file, -3) == $extension)
{
// On récupère les dimensions du fichier
$infos_img = getimagesize($_FILES['fichier']['tmp_name']);
// On vérifie les dimensions et taille de l'image
if(($infos_img[0] <= $width_max) && ($infos_img[1] <= $height_max) && ($_FILES['fichier']['size'] <= $max_size))
{
$count=mysql_query("SELECT COUNT(NumeroImage) FROM imagereduite;");
$nb_photos=mysql_result($count, 0);
$nb_photos=$nb_photos+1;
// Si c'est OK, on teste l'upload
$photo = 'photos_'.$nb_photos.'.jpg';
if(move_uploaded_file($_FILES['fichier']['tmp_name'],$target . $photo ) )
{
mysql_query ("INSERT INTO imagereduite SET LienImage='".$photo."', NomImage='" .$titre_photo ."', CommentaireImage='".$commentaire_photo."' ,NumeroRubrique=".$test.";");
echo ("INSERT INTO imagereduite SET LienImage='".$photo."', NomImage='" .$titre_photo ."', CommentaireImage='".$commentaire_photo."' ,NumeroRubrique=".$test.";");
// Si upload OK alors on affiche le message de réussite
echo '<b>Image uploadée avec succès !</b>';
echo '<hr />';
echo '<b>Fichier :</b> ', $photo, '<br />';
echo '<b>Taille :</b> ', $_FILES['fichier']['size'], ' Octets<br />';
echo '<b>Largeur :</b> ', $infos_img[0], ' px<br />';
echo '<b>Hauteur :</b> ', $infos_img[1], ' px<br />';
echo '<hr />';
echo '<br /><br />';
echo '<form enctype="multipart/form-data" action="ajout-image.php" method="post">
Chemin de l\'image : <input name="fichier" type="file" /><br /><br />
Titre de l\'image : <input name="titre" type="text" size="20" /><br /><br />
Description de l\'image : <textarea name="commentaire_photo" cols="20" rows="7">
</textarea><br /><br />
<input name="txt_nom" type="hidden" value="'.$nom_rubr.'" />
<input name="ajout" type="hidden" value="4">
<input type="submit" value="Ajouter l\'image" />
</form>';
}
else
{
// Sinon on affiche une erreur système
echo '<b>Problème lors de l\'upload !</b><br /><br /><b>', $_FILES['fichier']['error'], '</b><br /><br />';
}
}
else
{
// Sinon on affiche une erreur pour les dimensions et taille de l'image
echo '<b>Problème dans les dimensions ou taille de l\'image !</b><br /><br />';
}
}
else
{
// Sinon on affiche une erreur pour l'extension
echo '<b>Votre image ne comporte pas l\'extension .jpg !</b><br /><br />';
}
}
else
{
// Sinon on affiche une erreur pour le champ vide
echo '<b>Le champ du formulaire est vide !</b><br /><br />';
}
}
$test = $_POST['txt_nom'];
if ($_POST['ajout'] == 4)
{
$titre_photo=$_POST['titre'];
$commentaire_photo=$_POST['commentaire_photo'];
$nom_rubr=$test;
$req=mysql_query("SELECT NumeroRubrique FROM rubri WHERE NomRubrique='".$nom_rubr."';");
//$num_ope=mysql_result($req, 0);
while ($ligne = mysql_fetch_array($req) )
$num_rubr=$ligne[0];
$target = 'photos/agrandies/'; // Repertoire cible
$extension = 'jpg'; // Extension du fichier sans le .
$max_size = 10000000; // Taille max en octets du fichier
$width_max = 1000; // Largeur max de l'image en pixels
$height_max = 1000; // Hauteur max de l'image en pixels
//---------------------------------------------
// DEFINITION DES VARIABLES LIEES AU FICHIER
//---------------------------------------------
$nom_file = $_FILES['fichier']['name'];
$taille = $_FILES['fichier']['size'];
$tmp = $_FILES['fichier']['tmp_name'];
//----------------------
// SCRIPT D'UPLOAD
//----------------------
if(!empty($_FILES['fichier']['name']))
{
// On vérifie l'extension du fichier
if(substr($nom_file, -3) == $extension)
{
// On récupère les dimensions du fichier
$infos_img = getimagesize($_FILES['fichier']['tmp_name']);
// On vérifie les dimensions et taille de l'image
if(($infos_img[0] <= $width_max) && ($infos_img[1] <= $height_max) && ($_FILES['fichier']['size'] <= $max_size))
{
$count=mysql_query("SELECT COUNT(NumeroImage) FROM imageagrandie;");
$nb_photos=mysql_result($count, 0);
$nb_photos=$nb_photos+1;
// Si c'est OK, on teste l'upload
$photo = 'photos_'.$nb_photos.'.jpg';
if(move_uploaded_file($_FILES['fichier']['tmp_name'],$target . $photo ) )
{
mysql_query("INSERT INTO imageagrandie SET LienImage='".$photo."', NomImage='" .$titre_photo ."', CommentaireImage='".$commentaire_photo."', NumeroRubrique=".$test.";");
echo "INSERT INTO imageagrandie SET LienImage='".$photo."', NomImage='" .$titre_photo ."', CommentaireImage='".$commentaire_photo."', NumeroRubrique=".$test.";";
// Si upload OK alors on affiche le message de réussite
echo '<b>Image uploadée avec succès !</b>';
echo '<hr />';
echo '<b>Fichier :</b> ', $photo, '<br />';
echo '<b>Taille :</b> ', $_FILES['fichier']['size'], ' Octets<br />';
echo '<b>Largeur :</b> ', $infos_img[0], ' px<br />';
echo '<b>Hauteur :</b> ', $infos_img[1], ' px<br />';
echo '<hr />';
echo '<br /><br />';
}
else
{
// Sinon on affiche une erreur système
echo '<b>Problème lors de l\'upload !</b><br /><br /><b>', $_FILES['fichier']['error'], '</b><br /><br />';
}
}
else
{
// Sinon on affiche une erreur pour les dimensions et taille de l'image
echo '<b>Problème dans les dimensions ou taille de l\'image !</b><br /><br />';
}
}
else
{
// Sinon on affiche une erreur pour l'extension
echo '<b>Votre image ne comporte pas l\'extension .jpg !</b><br /><br />';
}
}
else
{
// Sinon on affiche une erreur pour le champ vide
echo '<b>Le champ du formulaire est vide !</b><br /><br />';
}
}
?> |
Partager