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
| if ((!empty($_POST['txtNom'])) OR (!empty($_POST['txtAlt'])) OR (!empty($_POST['fichier']))){
$content_dir = 'E:/EasyPHP1-8/www/CMS/galerie/'; // dossier où sera déplacé le fichier
$tmp_file = $_FILES['fichier']['tmp_name'];
$nom = $_POST["txtNom"] ;
if( !is_uploaded_file($tmp_file) )
{
exit("Le fichier est introuvable");
}
// on vérifie maintenant l'extension
$type_file = $_FILES['fichier']['type'];
if( !strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') )
{
exit("Le fichier n'est pas une image");
}
$src_im = ImageCreateFromJpeg($tmp_file);
$size = GetImageSize($tmp_file);
$src_w = $size[0];
$src_h = $size[1];
$test_w = 700;
$test_h = round(($test_w / $src_w) * $src_h);
if (($src_w > $src_h) AND ($test_h <= 500)){
$dst_w = 700;
$dst_h = round(($dst_w / $src_w) * $src_h);
$dst_im = ImageCreateTrueColor($dst_w,$dst_h);
ImageCopyResampled($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
}
else{
$dst_h = 500;
$dst_w = round(($dst_h / $src_h) * $src_w);
$dst_im = ImageCreateTrueColor($dst_w,$dst_h);
ImageCopyResampled($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
}
// on copie le fichier dans le dossier de destination
if( !move_uploaded_file($dst_im, $content_dir . $nom . ".jpg") )
{
exit("Impossible de copier le fichier dans $content_dir");
}
?>
<script type="text/javascript">
alert("Le fichier a bien été uploadé. Il a été redimensionné à <?php echo $dst_w ; ?> px de large et <?php echo $dst_h ; ?> px de haut.");
</script>
<?php
} |
Partager