par
blackshadows » 07 déc. 2011, 12:02
Bonjour,
Voici la solution a mon problème:
<?php
if(isset($_FILES['uploadFile'])){
$filename = $_FILES['uploadFile']['name'];
$path = pathinfo($filename);
echo $filesext = $path['extension'];
$filesext = strtolower($filesext);
$extensions_autorisees = array('jpg','jpeg','pjpg','pjpeg','jpg','png','gif','tiff');
$destpath = './uploads_img/';
if ($_FILES['uploadFile']['error'] <= 0){
}else{
$errors.='Erreur lors de l\'upload image';
exit($errors);
}
if ($_FILES['uploadFile']['size'] <= 2097152){
}else{
$errors.='L\'image est trop lourde';
exit($errors);
}
if(in_array($filesext,$extensions_autorisees)){
}else{
$errors.='Le type MIME de l\'image n\'est pas bon';
exit($errors);
}
$img = @getimagesize($_FILES['uploadFile']['tmp_name']);
if($filesext==='jpg' && ($img['mime']==='image/jpg' || $img['mime']==='image/jpeg' || $img['mime']==='image/pjpeg')){
$jpgimg = imagecreatefromjpeg($_FILES['uploadFile']['tmp_name']);
$tjpgimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tjpgimg[1] * (($newlarg)/$tjpgimg[0])) );
$newjpgimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newjpgimg,$jpgimg,0,0,0,0,$newlarg,$newhaut,$tjpgimg[0],$tjpgimg[1]);
imagedestroy($jpgimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagejpeg($newjpgimg ,$destpath.$filerename,100);
}
elseif($filesext==='png' && ($img['mime']==='image/png' || $img['mime']==='image/x-png')){
$pngimg = imagecreatefrompng($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagepng($newpngimg, $destpath.$filerename,0);
}
elseif($filesext==='gif' && ($img['mime']==='image/gif')){
$gifimg = imagecreatefromgif($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagegif($newpngimg, $destpath.$filerename,0);
}
else{
}
}else{
}
?>
Bonjour,
Voici la solution a mon problème:
[php]
<?php
if(isset($_FILES['uploadFile'])){
$filename = $_FILES['uploadFile']['name'];
$path = pathinfo($filename);
echo $filesext = $path['extension'];
$filesext = strtolower($filesext);
$extensions_autorisees = array('jpg','jpeg','pjpg','pjpeg','jpg','png','gif','tiff');
$destpath = './uploads_img/';
if ($_FILES['uploadFile']['error'] <= 0){
}else{
$errors.='Erreur lors de l\'upload image';
exit($errors);
}
if ($_FILES['uploadFile']['size'] <= 2097152){
}else{
$errors.='L\'image est trop lourde';
exit($errors);
}
if(in_array($filesext,$extensions_autorisees)){
}else{
$errors.='Le type MIME de l\'image n\'est pas bon';
exit($errors);
}
$img = @getimagesize($_FILES['uploadFile']['tmp_name']);
if($filesext==='jpg' && ($img['mime']==='image/jpg' || $img['mime']==='image/jpeg' || $img['mime']==='image/pjpeg')){
$jpgimg = imagecreatefromjpeg($_FILES['uploadFile']['tmp_name']);
$tjpgimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tjpgimg[1] * (($newlarg)/$tjpgimg[0])) );
$newjpgimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newjpgimg,$jpgimg,0,0,0,0,$newlarg,$newhaut,$tjpgimg[0],$tjpgimg[1]);
imagedestroy($jpgimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagejpeg($newjpgimg ,$destpath.$filerename,100);
}
elseif($filesext==='png' && ($img['mime']==='image/png' || $img['mime']==='image/x-png')){
$pngimg = imagecreatefrompng($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagepng($newpngimg, $destpath.$filerename,0);
}
elseif($filesext==='gif' && ($img['mime']==='image/gif')){
$gifimg = imagecreatefromgif($_FILES['uploadFile']['tmp_name']);
$tpngimg = getimagesize($_FILES['uploadFile']['tmp_name']);
$newlarg = 350;
$newhaut = ( ($tpngimg[1] * (($newlarg)/$tpngimg[0])) );
$newpngimg = imagecreatetruecolor($newlarg,$newhaut) or die ("Erreur");
imagecopyresampled($newpngimg,$pngimg,0,0,0,0,$newlarg,$newhaut,$tpngimg[0],$tpngimg[1]);
imagedestroy($pngimg);
$filerename = 'fichier_du_'.date('YmdHis').'.'.$filesext;
imagegif($newpngimg, $destpath.$filerename,0);
}
else{
}
}else{
}
?>
[/php]