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
| $path_big = "images/album";
$path_thumbs = "$path_big/mini";
$img_thumb_width = 160; // in pixel
$img_thumb_width2 = 700; // in pixel
$extlimit = "yes";
$limitedext = array(".gif",".jpg",".png",".jpeg");
if (!is_writeable($path_thumbs)){
die ("Erreur: Le dossier <b>($path_thumbs)</b> n'est pas accessible");
}
if (!is_writeable($path_big)){
die ("Erreur: Le dossier <b>($path_big)</b> n'est pas accessible");
}
//if the for has submittedd////////////////////////////////
if (isset($_POST['submit'])){
foreach ($_FILES['imgfile']['tmp_name'] as $key => $value) {
$file_tmp=$value;//nom reel de l'image
$file_type = $_FILES['imgfile']['type'][$key];
$file_name = $_FILES['imgfile']['name'][$key];
$file_size = $_FILES['imgfile']['size'][$key];
$desimg = $_POST['desimg'];
//check file extension//////////////////////
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
//echo "L'extension du fichier sélectionné n'est pas correcte. <br /><a href=\"#\">retour</a>";
exit();
}
//get the file extension./////////////////////
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
$sql = mysql_query(" INSERT INTO**************") or die( mysql_error());
//Recuperation du dernier id et renomage/////////////////
$rand_name = mysql_insert_id();
//get the new width variable.///////////////////////
$ThumbWidth = $img_thumb_width;
//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);
}
//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);
imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//save image
Imagepng ($resized_img,"$path_thumbs/$rand_name-mini.png");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
if ($width>700 OR $height>700 ){
// CONDITON DES 500 PIXELS
//get the new width variable./////////////////////// GROSSSE IMAGE/////////////
$ThumbWidth2 = $img_thumb_width2;
//keep image type///////////////////////////////
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img2 = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img2 = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img2 = imagecreatefromgif($file_tmp);
}
//list width and height and keep height ratio.//////////////////////
list($width, $height) = getimagesize($file_tmp);
$imgratio2=$width/$height;
if ($imgratio2>1){
$newwidth2 = $ThumbWidth2;
$newheight2 = $ThumbWidth2/$imgratio2;
}else{
$newheight2 = $ThumbWidth2;
$newwidth2 = $ThumbWidth2*$imgratio2;
}
$resized_img2 = imagecreatetruecolor($newwidth2,$newheight2);
imagecopyresized($resized_img2, $new_img2, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height);
//save image
Imagejpeg ($resized_img2,"$path_big/$rand_name.$file_ext");
ImageDestroy ($resized_img2);
ImageDestroy ($new_img2);
}}}
if ($width<700 OR $height<700 ){
//envoyer la grosse image SANS LA REDIMMENSIONNER /////////////////////
move_uploaded_file ($file_tmp, "$path_big/$aaa/$rand_name.$file_ext");
}}}} |
Partager