| 12
 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
 
 | <?php
$path_thumbs = "uploads";
$path_big = "uploads";
$img_thumb_width = 100;
$extlimit = "yes";
$limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
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 (isset($_POST['upForm'])){
$file_type = $_FILES['imgfile']['type'];
$file_name = $_FILES['imgfile']['name'];
$file_size = $_FILES['imgfile']['size'];
$file_tmp = $_FILES['imgfile']['tmp_name'];
if(!is_uploaded_file($file_tmp)){
echo "Erreur: Veuillez sélectionner une image. <a href='$_SERVER[PHP_SELF]'>Retour</a>";
exit();
}
$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. <a href='$_SERVER[PHP_SELF]'>Retour</a>";
exit();
}
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
$rand_name = md5(time());
$rand_name= rand(0,999999999);
$ThumbWidth = $img_thumb_width;
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, $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);
Imagejpeg ($resized_img,"$path_thumbs/$rand_name_mini.jpg");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
echo "Copier le lien";
}
move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
echo "<input type='text' name='TopicImage' value='../$path_big/$rand_name.$file_ext$data[CATIMAGE]' >";
echo "<br><a href='$_SERVER[PHP_SELF]'>Revenir a l'envoie de photo</a>";
}else{
echo
"<script>
function view_img(img_name){
document[img_name].src = upForm.imgfile.value;
document[img_name].width = 150;
}
</script>
<form method='post' name='upForm' enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' >
<input type='hidden' name='MAX_FILE_SIZE' value='200254' >
<input type='file' name='imgfile' >
<input type='Submit' name='upForm' value='Go' >
</form>";
}
?> | 
Partager