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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| <?php
//include('imageprof.php');
//session_start();
$_SESSION['id']=80;
if(isset($_POST['submit']))
{
$avatar=$_FILES['avatar']['name'];
$avatar_tmp=$_FILES['avatar']['tmp_name'];
//print_r($avatar);
//print_r($avatar_tmp);
$errors=array();
if(!empty($avatar_tmp))
{
$image=explode('.',$avatar);
//print_r($image);
$image_ext=end($image);
//print_r($image_ext);
if(in_array(strtolower($image_ext),array('png','gif','jpeg','jpg'))===false)
{
$errors[]="Veuillez saisir une image";
}
}
if(empty($errors))
{
////////////////////////////debut function/////////////////////
if(file_exists($avatar_tmp))
{
$image_size=getimagesize($avatar_tmp);
//print_r($image_size);
if($image_size['mime']=='image/png')
{
$image_src=imagecreatefrompng($avatar_tmp);
}else if($image_size['mime']=='image/gif')
{
$image_src=imagecreatefromgif($avatar_tmp);
}else if($image_size['mime']=='image/jpeg')
{
$image_src=imagecreatefromjpeg($avatar_tmp);
}else
{
echo"Votre image n'est pas valide";
$image_src=false;
}
if($image_src !==false)
{
$image_width=300;
if($image_size[0]<=$image_width)
{
$image_finale=$image_src;
}else{
$new_width[0]=$image_width;
$new_height[1]=($image_size[1]/$image_size[0])*$image_width;
$image_finale=imagecreatetruecolor($new_width[0],$new_height[1]);
imagecopyresampled($image_finale,$image_src,0,0,0,0,$new_width[0],$new_height[1],$image_size[0],$image_size[1]);
}
}
imagejpeg($image_finale,'http://www.xxxxxx.fr/wp-content/test/image/'.$_SESSION['id'].'.jpg');
}
/////////////////////////////fin function//////////////////////
}else{
foreach($errors as $error)
{
echo $error;
}
}
}
?>
<html>
<head>
<body>
<p><img src="http://www.xxxxxxx.fr/wp-content/test/image/<?php echo $_SESSION['id'];?>.jpg" alt="avatar"/></p>
<form method="POST" action="" enctype="multipart/form-data">
<input type="file" name="avatar"/><br/>
<input type="submit" value="upload" name="submit"/>
</form>
</body>
</head>
</html> |
Partager