Bonjour,

J'ai mon script d'envoi d'image qui marche trés bien mais cependant je voudrai lui rajouter 2 option ....

1 - Control du poinds de l'image maxi a 600 Ko ca m'eviterai davoir des image de 8 MO ....
2 - Redimmensionnement de la taille de l'image a 600 Pixels (la miniature est deja generer par le script ... ca m'evitera d'avoir des photo de 1600*1200 pixel a afficher sur le site et de m'enregsitrer l'image en 600 pixels en PNG .... j'ai essayer de faire comme la miniature mais je me suis embrouiller dans les variables ...



Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
$path_big = "image_up/photos_carnet";
$path_thumbs = "$path_big/mini";
 
//the new width of the resized image.
$img_thumb_width = 100; // in pixel
 
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded (yes/no)
//allowed Extensions
$limitedext = array(".gif",".jpg",".png",".jpeg");
 
 
//check if folders are Writable or not
//please CHOMD them 777
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];
 
//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 up_image2 SET  nom_image ='$file_ext', id_auteur ='$id_auteur', rubrique = '$rubrique', description = 'blabla', id_parent  = '15' ") 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);
 
 
echo "<br>Image Thumb: <a href=\"$path_thumbs/$rand_name _mini.png\" target=\"_new\" >$path_thumbs/$rand_name _mini.png</a>";
 
 
 
}
 
 
 
//envoyer la grosse image/////////////////////
move_uploaded_file ($file_tmp, "$path_big/$aaa/$rand_name.$file_ext");
 
echo "<br>grosse image: <a href=\"$path_big/$rand_name.$file_ext\" target=\"_new\">$path_big/$rand_name.$file_ext</a>";
 
echo "<br /><h3>merci</h3>";
echo "<div class=\"alerte\">Merci <b><? $auteur ?></b>Merci</div>";
}}
 
}
?>