$_FILES['resim']['type'] != "image/jpeg" && $_FILES['resim']['type'] != "image/jpg" |
$_FILES['resim']['type'] != "image/gif" && $_FILES['resim']['type'] != "image/gif" |
$_FILES['resim']['type'] != "image/png" && $_FILES['resim']['type'] != "image/png")
{
echo '<div style="width:100%; height:25px; padding-left:20px; font-weight:bold;">Resim yüklemediniz veya formatı yanlış lütfen tekrar deneyiniz.</div>';
}else {
if($_FILES['resim']['type'] == "image/jpeg" | $_FILES['resim']['type'] == "image/gif" | $_FILES['resim']['type'] == "image/png")
$uzanti=".jpg , .png , .gif";
$uploadedfile = $_FILES['resim']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$zufall = rand(1,9999);
$newwidth=500;
$newheight=($height/$width)*500;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$resim_kucuk = "../araclar/$zufall".'-'. $_FILES['resim']['name'];
imagejpeg($tmp,$resim_kucuk,100);
imagedestroy($src);
imagedestroy($tmp);Yukarıdaki kod yerine aşağıdakini kullandım, başka arkadaşlarımıza lazım olabilir diye ekliyorum.
switch($_FILES['resim']['type']) {
case 'image/png';
echo 'ieaieaie';
$uzanti='png'; $olustur=imagecreatefrompng($_FILES['resim']['tmp_name']); $alinanGrafik=true; break;
case 'image/jpeg';
$uzanti='jpg'; $olustur=imagecreatefromjpeg($_FILES['resim']['tmp_name']); $alinanGrafik=true; break;
case 'image/pjpeg';
$uzanti='jpg'; $olustur=imagecreatefromjpeg($_FILES['resim']['tmp_name']); $alinanGrafik=true; break;
case 'image/gif';
$uzanti='gif'; $olustur=imagecreatefromgif($_FILES['resim']['tmp_name']); $alinanGrafik=true; break;
default: $alinanGrafik=false;
}
if($alinanGrafik==true) {
list($width,$height)=getimagesize($_FILES['resim']['tmp_name']);
$zufall = rand(1,9999);
$newwidth=500;
$newheight=($height/$width)*500;
$tmp=imagecreatetruecolor($newwidth,$newheight);
if($uzanti == 'gif' or $uzanti == 'png') {
imagecolortransparent($tmp, imagecolorallocatealpha($tmp, 0, 0, 0, 127));
imagealphablending($tmp, false);
imagesavealpha($tmp, true);
}
imagecopyresampled($tmp,$olustur,0,0,0,0,$newwidth,$newheight,$width,$height);
//$resim_kucuk = "../araclar/$zufall". $_FILES['resim']['name'];
$resim_kucuk = '../araclar/'. $_FILES['resim']['name'];
switch($uzanti) {
case 'png'; imagepng($tmp, $resim_kucuk); $sonuc=true; break;
case 'jpg'; imagejpeg($tmp, $resim_kucuk); $sonuc=true; break;
case 'gif'; imagegif($tmp, $resim_kucuk); $sonuc=true; break;
default: $sonuc=false;
}
imagedestroy($olustur);
imagedestroy($tmp);
if($sonuc==true) {
//$resim= "../slider/$zufall".$_FILES["resim"]["name"];
$resim='../araclar/'.$_FILES['resim']['name'];
move_uploaded_file($_FILES["resim"]["tmp_name"],$resim);