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
|
<?php
//actavation de la session + connexion sql
session_start();
include('../fonction/config.php');
connect_sql();
//RECUPERATION DES id_user et création du nom du fichier final $time_$jour*$mois*$annee*$annee+$id_user.jpg
$id_user = $_SESSION['id'];
$time = time();
$jour = date("d");
$mois = date("m");
$annee = date("Y");
$jourmoisanne = $jour*$mois*$annee*$annee+$id_user;
$name_fichier_de_sortie = $time.'_'.$jourmoisanne;
//fonction d'upload
function cImage($max,$source,$dest){
$size = getimagesize($source);
$w = $size[0];
$h = $size[1];
$simg = imagecreatefromjpeg($source);
$dimg = imagecreatetruecolor($max,$max);
$wm = $w/$max;
$hm = $h/$max;
$h_height = $max/2;
$w_height = $max/2;
if($w > $h){
$adjusted_width = $w / $hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$max,$w,$h);
}elseif(($w < $h) || ($w == $h)){
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 3;
$int_height = $half_height - $h_height;
if($int_height < 0) $int_height = 0;
imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$max,$adjusted_height,$w,$h);
}else{
imagecopyresampled($dimg,$simg,0,0,0,0,$max,$max,$w,$h);
}
imagejpeg($dimg,$dest,100);
}
//on effectue le script
if(cImage(50,$_FILES['fichier']['name'],'../img/photo/50/'.$name_fichier_de_sortie.'.jpg'))
{
header('location: ../ok');
}
else
{
// Sinon on affiche une erreur système
header('location: ../erreur'); }
?> |
Partager