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
|
//chemin où stocker la petite et grand image
$path_thumbs = "../photos/".$_GET['num_bebe']."";
$path_big = "../photos/".$_GET['num_bebe']."";
//nouvelle taille de l'image
$img_thumb_width = 130; // en pixcel
$img_thumb_width2 = 640; // en pixcel
$extlimit = "yes"; //Est ce que vous voulez limiter l'extension des fichiers ?(yes/no)
// Extensions autorisés
$limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
// CREATION DES DOSSIERS POUR STOCKER LES PHOTOS
// Controle sur le dossier de destination est bien en RW
// please CHOMD them 777
if (!is_writeable($path_thumbs)){
mkdir ("../photos/".$_GET['num_bebe']."", 0777);
}
if (!is_writeable($path_big)){
mkdir ("../photos/".$_GET['num_bebe']."", 0777);
}
// QUAND ON VALIDE LE FORMULAIRE
if (isset($_POST['upForm'])){
$file_type = $_FILES['imgfile']['type'];
$file_name = $_FILES['imgfile']['name'];
$file_size = $_FILES['imgfile']['size'];
$file_tmp = $_FILES['imgfile']['tmp_name'];
// On regarde si on a bien rempli le champ parcourir
// dans le cas ou l'extension est mauvaise ou rien selectionné
if(!is_uploaded_file($file_tmp)){
echo "<img src='image/erreur.png' /> Veuillez sélectionner une image valide. <br /><br />
<a href=\"$_SERVER[REQUEST_URI]\">[ Retour ]</a>";
exit(); // on quitte le script
}
// controle l'extension du fichier
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "<img src='image/erreur.png' /> L'extension du fichier sélectionné n'est pas correcte. <br /><br />
<a href=\"$_SERVER[REQUEST_URI]\"><center>[ Retour ]</center></a>";
exit();
}
//on recupere l'extension du fichier
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name = md5(time());
$rand_name= rand(0,999999999);
//get the new width variable.
$ThumbWidth = $img_thumb_width;
$ThumbWidth2 = $img_thumb_width2;
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img = imagecreatefromgif($file_tmp);
}elseif($file_type == "image/jpg"){
$new_img = imagecreatefromgif($file_tmp);
}
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}
$resized_img = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//save image
Imagepng ($resized_img,"$path_thumbs/$rand_name".'_mini.png');
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth2;
$newheight = $ThumbWidth2/$imgratio;
}else{
$newheight = $ThumbWidth2;
$newwidth = $ThumbWidth2*$imgratio;
}
$resized_img = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//save image
$file_ext = strtolower($file_ext);
Imagepng ($resized_img,"$path_thumbs/$rand_name.$file_ext");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
} |
Partager