<?php

/**
* @author Leon Kuipers
* @copyright 2012
*/


include "connect.php";

if(isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$size_orgineel = $_FILES['myfile']['size'];
$tmp_name = $_FILES['myfile']['tmp_name'];
$extentions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG', 'GIF', 'PNG');

if ($name)
{
if(@!getimagesize($_FILES['myfile']['tmp_name']))
{
echo 'Deze foto heeft geen breedte of hoogte.';
}
else
{
if(!in_array(strtolower(strrchr($_FILES['myfile']['name'], '.')), $extentions))
{
echo 'Deze foto extentie is niet toegestaan';
}
else
{
//info over de afbeelding
$location_orgineel = 'afbeelding_orgineel/'.$name;
move_uploaded_file($tmp_name,$location_orgineel);
$imagearray = getimagesize($location_orgineel);
$width_orgineel = $imagearray[0];
$height_orgineel = $imagearray[1];
$image_extention = pathinfo($name, PATHINFO_EXTENSION);
$format_midium = 500;
$format_small = 125;

// afbeelding check
if ($width_orgineel == $height_orgineel)
{
$case = 1;
}
if ($width_orgineel > $height_orgineel)
{
$case = 2;
}
if ($width_orgineel < $height_orgineel)
{
$case = 3;
}

switch ($case)
{
// breete en lenge evenlang
case 1:
//meidium
$height_midium = $format_midium;
$width_midium = $format_midium;
//small
$height_small = $format_small;
$width_small = $format_small;
break;

// breete breeder dan de lengte
case 2:
$height_midium = $format_midium;
$ratio_midium = $height_midium / $height_orgineel;
$width_midium = round($width_orgineel * $ratio_midium);
//small
$height_small = $format_small;
$ratio_small = $height_small / $height_orgineel;
$width_small = round($width_orgineel * $ratio_small);
break;

// hoogte hooger dan de breete
case 3:
//midium
$width_midium = $format_midium;
$ratio_midium = $width_midium / $width_orgineel;
$height_midium = round($height_orgineel * $ratio_midium);
//small
$width_small = $format_small;
$ratio_small = $width_small / $width_orgineel;
$height_small = round($height_orgineel * $ratio_small);
break;
}


switch ($image_extention)
{
case "png":
case "PNG":
$image_create = imagecreatefrompng($location_orgineel);
break;

case "bmp":
case "WBMP":
$image_create = imagecreatefromwbmp($location_orgineel);
break;

case "gif":
case "GIF":
$image_create = imagecreatefromgif($location_orgineel);
break;

case "jpg":
case "JPG":
$image_create = imagecreatefromjpeg($location_orgineel);
break;

case "jpeg":
case "JPEG":
$image_create = imagecreatefromjpeg($location_orgineel);
break;

}
//midium
$Thumbnail_empty_medium = imagecreatetruecolor($width_midium, $height_midium);
imagecopyresampled($Thumbnail_empty_medium, $image_create, 0, 0, 0, 0, $width_midium, $height_midium, $width_orgineel, $height_orgineel);
$thumbnail_naam_medium = 'afbeelding_midium/'.$name;
//small
$Thumbnail_empty_small = imagecreatetruecolor($width_small, $height_small);
imagecopyresampled($Thumbnail_empty_small, $image_create, 0, 0, 0, 0, $width_small, $height_small, $width_orgineel, $height_orgineel);
$thumbnail_naam_small = 'afbeelding_small/'.$name;


switch ($image_extention)
{
case "png":
case "PNG":
//midium
imagepng($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;

case "bmp":
case "BMP":
//midium
imagewbmp($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;

case "gif":
case "GIF":
//midium
imagegif($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;

case "jpg":
case "JPG":
//midium
imagejpeg($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;

case "jpeg":
case "JPEG":
//midium
imagejpeg($Thumbnail_empty_medium, $thumbnail_naam_medium);
//small
imagepng($Thumbnail_empty_small, $thumbnail_naam_small);
break;

}

}
}
}
else
{
die("Selecteer een afbeelding!");
}
}
echo 'uploaden maar';

echo "<br/><br/>
<form action='upload.php' method='POST' enctype='multipart/form-data' />
Image uploaden: &nbsp;
<input type='file' name='myfile' />
<input type='submit' name='submit' value='Uploaden!' />
</form>
";
?>
Kleine opmerking: Als er meerdere case-waarden dezelfde handelingen moeten ondergaan kan dat simpeler.

<?php
// niet zo
case "png":
$image_create = imagecreatefrompng($location_orgineel);
break;

case "PNG":
$image_create = imagecreatefrompng($location_orgineel);
break;

// maar zo
case "png":
case "PNG":
$image_create = imagecreatefrompng($location_orgineel);
break;
?>
- SanThe - op 06/05/2012 16:17:01

Kleine opmerking: Als er meerdere case-waarden dezelfde handelingen moeten ondergaan kan dat simpeler.

<?php
// niet zo
case "png":
$image_create = imagecreatefrompng($location_orgineel);
break;

case "PNG":
$image_create = imagecreatefrompng($location_orgineel);
break;

// maar zo
case "png":
case "PNG":
$image_create = imagecreatefrompng($location_orgineel);
break;
?>


oke dank, ik ga t veranderen
Zoals jij het nu hebt is het ook goed hoor. Echter het scheelt een hoop typwerk en het onderhoud is ook eenvoudiger.
dat is waar maar als je ipv 1000 regels maar 500 hoeft te typen, en ik ben liever lui dan moe hahahaha,

Reageren