oops j'ai oublié de push
This commit is contained in:
parent
4f41366010
commit
fed88a764b
15 changed files with 130 additions and 35 deletions
|
|
@ -217,9 +217,81 @@ class UserCtrl extends MotherCtrl {
|
|||
}else{
|
||||
$objUser->hydrate($_POST);
|
||||
$objUser->setId($_SESSION['user']['user_id']);
|
||||
|
||||
// Vérification de l'image
|
||||
$arrTypeAllowed = array('image/jpeg', 'image/png', 'image/webp');
|
||||
$boolImageOk = true;
|
||||
|
||||
if ($_FILES['image']['error'] != 4) {
|
||||
if (!in_array($_FILES['image']['type'], $arrTypeAllowed)) {
|
||||
$arrError['image'] = "Le type de fichier n'est pas autorisé";
|
||||
} else {
|
||||
switch ($_FILES['image']['error']) {
|
||||
case 0:
|
||||
$strImageName = uniqid() . ".webp";
|
||||
$strOldImg = $objUser->getImage();
|
||||
$objUser->setImage($strImageName);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
$arrError['image'] = "Le fichier est trop volumineux";
|
||||
break;
|
||||
case 3:
|
||||
$arrError['image'] = "Le fichier a été partiellement téléchargé";
|
||||
break;
|
||||
case 6:
|
||||
$arrError['image'] = "Le répertoire temporaire est manquant";
|
||||
break;
|
||||
default:
|
||||
$arrError['image'] = "Erreur sur l'image";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Traitement de l'image si pas d'erreur
|
||||
if (count($arrError) == 0 && isset($strImageName)) {
|
||||
$strDest = $_ENV['IMG_USER_PATH'] . $strImageName;
|
||||
$strSource = $_FILES['image']['tmp_name'];
|
||||
list($intWidth, $intHeight) = getimagesize($strSource);
|
||||
|
||||
$intDestWidth = 200; $intDestHeight = 200;
|
||||
$fltDestRatio = $intDestWidth / $intDestHeight;
|
||||
$fltSourceRatio = $intWidth / $intHeight;
|
||||
|
||||
if ($fltSourceRatio > $fltDestRatio) {
|
||||
$intCropHeight = $intHeight;
|
||||
$intCropWidth = (int)round($intHeight * $fltDestRatio);
|
||||
$intCropX = (int)(($intWidth - $intCropWidth) / 2);
|
||||
$intCropY = 0;
|
||||
} else {
|
||||
$intCropWidth = $intWidth;
|
||||
$intCropHeight = (int)round($intWidth / $fltDestRatio);
|
||||
$intCropX = 0;
|
||||
$intCropY = (int)(($intHeight - $intCropHeight) / 2);
|
||||
}
|
||||
|
||||
$objDest = imagecreatetruecolor($intDestWidth, $intDestHeight);
|
||||
switch ($_FILES['image']['type']) {
|
||||
case 'image/jpeg': $objSource = imagecreatefromjpeg($strSource); break;
|
||||
case 'image/png': $objSource = imagecreatefrompng($strSource); break;
|
||||
case 'image/webp': $objSource = imagecreatefromwebp($strSource); break;
|
||||
}
|
||||
|
||||
imagecopyresampled($objDest, $objSource, 0, 0, $intCropX, $intCropY, $intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight);
|
||||
$boolImageOk = imagewebp($objDest, $strDest);
|
||||
imagedestroy($objDest);
|
||||
imagedestroy($objSource);
|
||||
}
|
||||
|
||||
|
||||
$boolInsert = $objUserModel->update($objUser);
|
||||
|
||||
if ($boolInsert === true) {
|
||||
if (isset($strOldImg) && !empty($strOldImg) && isset($strImageName)) {
|
||||
$strOldFile = $_ENV['IMG_USER_PATH'] . $strOldImg;
|
||||
if (file_exists($strOldFile)) unlink($strOldFile);
|
||||
}
|
||||
$arrNewInfo = $objUserModel->findUserByPseudo($objUser->getPseudo());
|
||||
$_SESSION['user'] = $arrNewInfo;
|
||||
$_SESSION['success'] = "Compte modifier avec succès";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue