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
|
<?php
if($_SESSION['id'])
{
/************************************************************
*************************************************************/
/************************************************************
Definition des constantes / tableaux et variables
*************************************************************/
// Constantes
define('TARGET', 'images/film/'); // Repertoire cible
define('MAX_SIZE', 100000); // Taille max en octets du fichier
define('WIDTH_MAX', 200); // Largeur max de l'image en pixels
define('HEIGHT_MAX', 200); // Hauteur max de l'image en pixels
// Tableaux de donnees
$tabExt = array('jpg','gif','png','jpeg'); // Extensions autorisees
$infosImg = array();
// Variables
$extension = NULL;
$message = NULL;
/************************************************************
Creation du repertoire cible si inexistant
*************************************************************/
if( !is_dir(TARGET) ) {
if( !mkdir(TARGET, 0700) ) {
exit('Erreur : le répertoire cible ne peut-être creé ! Vérifiez que vous diposiez des droits suffisants pour le faire ou créez le manuellement !');
}
}
/************************************************************
Script d'upload
*************************************************************/
if(isset($_POST['ajouter']))
{
// On verifie si le champ est rempli
if( !empty($_FILES['image']['name']) )
{
// Recuperation de l'extension du image
$extension = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
// On verifie l'extension du image
if(in_array(strtolower($extension),$tabExt))
{
// On recupere les dimensions du image
$infosImg = getimagesize($_FILES['image']['tmp_name']);
// On verifie le type de l'image
if($infosImg[2] >= 1 && $infosImg[2] <= 14)
{
// On verifie les dimensions et taille de l'image
if(($infosImg[0] <= WIDTH_MAX) && ($infosImg[1] <= HEIGHT_MAX) && (filesize($_FILES['image']['tmp_name']) <= MAX_SIZE))
{
// Si c'est OK, on teste l'upload
$select = 'SELECT count(id_film) FROM film';
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
$row = mysql_fetch_row($result) ;
if ($_FILES['image']['type'] == 'image/jpeg'){$extention = '.jpeg';}
if ($_FILES['image']['type'] == 'image/png'){$extention = '.png';}
if ($_FILES['image']['type'] == 'image/jpg'){$extention = '.jpg';}
if ($_FILES['image']['type'] == 'image/gif'){$extention = '.gif';}
$NomImage = $row[0]+1;
$NomImage .= $extention;
if(move_uploaded_file($_FILES['image']['tmp_name'], TARGET.$NomImage))
{
$nom=strip_tags($_POST["nom"]); $desc=strip_tags($_POST["desc"]);
$lien=strip_tags($_POST["lien"]); $genre=strip_tags($_POST["genre"]);
$duree=strip_tags($_POST["duree"]); $dat=strip_tags($_POST["dat"]);
$pays=strip_tags($_POST["pays"]);
// Message de reussite
$result = mysql_query("INSERT INTO film VALUES('', '".TARGET.$NomImage."', '".$nom."','".$desc."',
'".$lien."', '".$genre."','".$duree."','".$dat."', '".$pays."','".$_SESSION['id']."')")
or die ('Erreur : '.mysql_error() );
if($result){$message = 'Film ajouter avec sucsé !';}
else {$message = 'Probleme lors de l\'ajout du film !';}
}
else
{
// Sinon on affiche une erreur systeme
$message = 'Problème lors de l\'upload !';
}
}
else
{
// Sinon erreur sur les dimensions et taille de l'image
$message = 'Erreur dans les dimensions de l\'image !';
}
}
else
{
// Sinon erreur sur les dimensions et taille de l'image
$message = 'L\'image à uploader n\'est pas une image !';
}
}
else
{
// Sinon on affiche une erreur pour l'extension
$message = 'L\'extension de l\'image est incorrecte !';
}
}
else
{
// Sinon on affiche une erreur pour le champ vide
$message = 'Veuillez remplir le formulaire svp !';
}
}
/************************************************************
Formulaire XHTML
*************************************************************/
?>
<title>Ajouter nouveau film KechMovies</title>
<div class="left_content">
<div class="cim"><p class="title">Ajouter un nouveau film</p>
</div>
<p class="story" ><br />
<div align="center">
<strong style="color:#FFF">Extention autoriser pour l image : jpg, gif, png, jpeg. <br />
Taille maximale de l image 400 ko. <br />
Hauteur et largeur maximum pour limage 200 px. </strong>
</div>
<br />
<!-- Debut du formulaire -->
<form enctype="multipart/form-data" method="post" name="AddFilm" onsubmit="return VerifChampAddFilm()">
<table bordercolor="#333333" bgcolor="#666666" style="color:#FFF;" width="520" border="5" align="center" cellpadding="0" cellspacing="7" >
<tr>
<td align="right"><strong class="blanc_18px">Nom : </strong></td>
<td width="57%" align="left"><input name="nom" type="text" size="50"></td>
</tr>
<tr>
<td align="right" width="43%"><strong class="blanc_18px">Description : </strong></td>
<td align="left"><textarea name="desc" cols="39" rows="7"></textarea></td>
</tr>
<tr>
<td align="right" width="43%"><strong class="blanc_18px">Image : </strong></td>
<td align="left">
<input type="hidden" name="posted" value="1" />
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_SIZE; ?>" />
<input name="image" type="file" size="34" />
</td>
</tr>
<tr>
<td align="right" width="43%"><strong class="blanc_18px">Genre : </strong></td>
<td align="left"><input name="genre" type="text" size="50"></td>
</tr>
<tr>
<td align="right" width="43%"><strong class="blanc_18px">Duree : </strong></td>
<td align="left"><input name="duree" type="text" size="50" value="-h --min"></td>
</tr>
<tr>
<td align="right" width="43%"><strong class="blanc_18px">Dat : </strong></td>
<td align="left"><input name="dat" type="text" size="50"></td>
</tr>
<tr>
<td align="right" width="43%"><strong class="blanc_18px">Pays : </strong></td>
<td align="left"><input name="pays" type="text" size="50"></td>
</tr>
<tr>
<td align="right" width="43%"><strong class="blanc_18px">Lien MegaUpload : </strong></td>
<td align="left"><input name="lien" type="text" size="50"></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="ajouter" type="submit" value="Ajouter" ></td>
</tr>
</table>
<!-- Fin du formulaire -->
</p>
<p class="author"> </p>
<?php
if( !empty($message) ) {
echo '<center><p>',"\n";
echo "\t\t<strong>", htmlspecialchars($message) ,"</strong>\n";
echo "\t</p>\n\n</center>";
}
}
else
{ ?><SCRIPT>setTimeout('top.location.href="javascript:history.back()"',"0")</SCRIPT>
<?php exit;}
?>
</div> |
Partager