<?php
// ------------------------------------------------------------
// DEFINITION DES VARIABLES
// ------------------------------------------------------------
$target = "upload/"; // Repertoire cible
$target2 = "mini/"; // Repertoire cible
$max_size = 4194304; // Taille max en octets du image
$width_max = 2000; // Largeur max de l'image en pixels
$height_max = 2000; // Hauteur max de l'image en pixels
$extensions_ok = array("jpeg","jpg","gif","png","bmp");
//------------------------------------------------------------
// SCRIPT DE CHANGEMENT D`URL
//------------------------------------------------------------
if ($_FILES['image']['type'] == 'image/jpeg') { $extention = '.jpeg'; } { $extention2 = 'jpeg'; }
if ($_FILES['image']['type'] == 'image/jpg') { $extention = '.jpg'; } { $extention2 = 'jpg'; }
if ($_FILES['image']['type'] == 'image/png') { $extention = '.png'; } { $extention2 = 'png'; }
if ($_FILES['image']['type'] == 'image/gif') { $extention = '.gif'; } { $extention2 = 'gif'; }
if ($_FILES['image']['type'] == 'image/bmp') { $extention = '.bmp'; } { $extention2 = 'bmp'; }
$mini_name = time().$extention;
$nom_image = $target.time().$extention;
$mini = "mini";
$nom_imagemini = time().$mini.$extention;
$nom_imagemini2 = time().$mini.$extention;
//------------------------------------------------------------
// DEFINITION DES VARIABLES LIEES AU IMAGES
//------------------------------------------------------------
$nom_file = $_FILES['image']['name'];
$taille = $_FILES['image']['size'];
$tmp = $_FILES['image']['tmp_name'];
$chemin = $target.$_FILES['image']['tmp_name'];
$url = 'http://www.butterfly-party.com/fakupload/upload/' .$nom_image. '';
$url2 = '[
url=http://www.butterfly-party.com/fakupload/upload/' .$nom_image. '][
img]http://www.butterfly-party.com/fakupload/mini/' .$nom_imagemini2. '[/img][/url]';
$url3 = $target2 .$nom_imagemini2;
$url4 = 'http://www.butterfly-party.com/fakupload/' .$nom_image. '';
$url5 = '[
url=http://www.butterfly-party.com/fakupload/][
img]http://www.butterfly-party.com/fakupload/mini/' .$nom_imagemini2. '[/img][/url]';
$url6 = $target2 .$nom_imagemini2;
$extension = substr($nom_file,-3); // Récupération de l'extension
//------------------------------------------------------------
// SCRIPT DE CREATION DE MINIATURE
//------------------------------------------------------------
if ($_FILES['image']['type'] == 'image/jpeg')
{
$source = imagecreatefromjpeg($tmp); // La photo est la source
$destination = imagecreatetruecolor(100, 100); // On crée la miniature vide
// Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);
$largeur_destination = imagesx($destination);
$hauteur_destination = imagesy($destination);
// On crée la miniature
imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source);
// On enregistre la miniature
imagejpeg($destination, "/home/axel/public_html/fakupload/mini/" .$nom_imagemini);
imagedestroy($destination);
}
if ($_FILES['image']['type'] == 'image/png')
{
$source = imagecreatefrompng($tmp); // La photo est la source
$destination = imagecreatetruecolor(100, 100); // On crée la miniature vide
// Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);
$largeur_destination = imagesx($destination);
$hauteur_destination = imagesy($destination);
// On crée la miniature
imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source);
// On enregistre la miniature
imagepng($destination, "/home/axel/public_html/fakupload/mini/" .$nom_imagemini);
imagedestroy($destination);
}
if ($_FILES['image']['type'] == 'image/gif')
{
$source = imagecreatefromgif($tmp); // La photo est la source
$destination = imagecreatetruecolor(100, 100); // On crée la miniature vide
// Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);
$largeur_destination = imagesx($destination);
$hauteur_destination = imagesy($destination);
// On crée la miniature
imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source);
// On enregistre la miniature
imagegif($destination, "/home/axel/public_html/fakupload/mini/" .$nom_imagemini);
imagedestroy($destination);
}
if ($_FILES['image']['type'] == 'image/bmp')
{
$source = imagecreatefromwbmp($tmp); // La photo est la source
$destination = imagecreatetruecolor(100, 100); // On crée la miniature vide
// Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);
$largeur_destination = imagesx($destination);
$hauteur_destination = imagesy($destination);
// On crée la miniature
imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source);
// On enregistre la miniature
imagewbmp($destination, "/home/axel/public_html/fakupload/mini/" .$nom_imagemini);
imagedestroy($destination);
}
//------------------------------------------------------------
// SCRIPT D'UPLOAD
//------------------------------------------------------------
if($_POST['envoie'])
{
// On vérifie si le champ est rempli
if($_FILES['image']['tmp_name'])
{
// On vérifie l'extension du image
if(in_array(strtolower($extension),$extensions_ok))
{
// On récupère les dimensions du image
$infos_img = getimagesize($_FILES['image']['tmp_name']);
// On vérifie les dimensions et taille de l'image
if(($infos_img[0] <= $width_max) && ($infos_img[1] <= $height_max) && ($taille <= $max_size))
{
// Si c'est OK, on teste l'upload
if(move_uploaded_file($tmp,$nom_image))
{
// Si upload OK alors on affiche le message de réussite
echo '<h2>Validation de l\'upload</h2>
<p><a href="' . $url4 . '"><img src="' . $url6 . '" width="100" height="100" border="none" /></a><BR><BR>
Url de l\'image simple:<BR>
<input type="text" size="100" value=" ' . $url4 . '" />
<br /><br />Url pour les forums:<BR><input type="text" size="100" value="' . $url5 . '" /><br /></p>';
}
else
{
// Sinon on affiche une erreur système
echo '<h2>Erreur du System !</h2>
<p><font color="red"><img src="./utils/attention.gif" alt="attention" height="20" width="20"> Erreur du systéme veuillez contactez le <a href="index.php?page=contact">webmaster</a></font>
</p>';
}
}
else
{
// Sinon erreur sur les dimensions et taille de l'image
echo '<h2>Erreur de la dimension de l\'image</h2>
<p>
<font color="red"><img src="./utils/attention.gif" alt="attention" height="20" width="20"> Erreur de la dimension</font>
</p>';
}
}
else
{
// Sinon on affiche une erreur pour l'extension
echo '<h2>Erreur de l\'extension</h2>
<p><font color="red">
<img src="./utils/attention.gif" alt="attention" height="20" width="20"> Erreur de l\'extension</font>
</p>';
}
}
else
{
// Sinon on affiche une erreur pour le champ vide
echo '<h2>Erreur le champ est vide</h2>
<p><font color="red"><img src="./utils/attention.gif" alt="attention" height="20" width="20"> Erreur de le champ est vide</font>
</p>';
}
}
?>
Partager