<?php session_start ();
error_reporting(E_ALL);
$datum = date("dmy");
$zeit = date("Hi");
$dat = $datum.$zeit;
if(isset( $_FILES['file'] ))
{
for( $i = 0; $i < count($_FILES['file']['error']); ++$i )
{
if( $_FILES['file']['error'][$i] === 0
&& is_uploaded_file( $_FILES['file']['tmp_name'][$i] ))
{
$tempname = $_FILES['file']['tmp_name'][$i];
$name = $_FILES['file']['name'][$i];
$size = getimagesize("$tempname");
if (!copy($tempname, 'foto/temp_'.$name))
{
echo ('Fehler beim Original erstellen -> '.$originalname.'...<br>\n');
}
$dir = "foto/";
$original = "temp_$name";
$get_data = getimagesize("$dir"."$original");
if($get_data[2]==1)
{
$original_temp = imagecreatefromgif("$dir"."$original");
$height_orig = $get_data[1];
$width_orig = $get_data[0];
$width = 500;
$height = intval($height_orig*$width/$width_orig);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
$newOriginal = imagecreatetruecolor($width, $height);
imagecopyresampled($newOriginal, $original_temp, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagegif($newOriginal, "$dir"."$dat$name", 100);
}
if($get_data[2]==2)
{
$original_temp = imagecreatefromjpeg("$dir"."$original");
$height_orig = $get_data[1];
$width_orig = $get_data[0];
$width = 500;
$height = intval($height_orig*$width/$width_orig);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
$newOriginal = imagecreatetruecolor($width, $height);
imagecopyresampled($newOriginal, $original_temp, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($newOriginal, "$dir"."$dat$name", 100);
}
if($get_data[2]==3)
{
$original_temp = imagecreatefrompng("$dir"."$original");
$height_orig = $get_data[1];
$width_orig = $get_data[0];
$width = 500;
$height = intval($height_orig*$width/$width_orig);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
$newOriginal = imagecreatetruecolor($width, $height);
imagecopyresampled($newOriginal, $original_temp, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($newOriginal, "$dir"."$dat$name", 100);
}
$delete = "$dir"."temp_$name";
unlink($delete);
if (is_uploaded_file($tempname))
{
if($size[2]==1)
{
$im_temp = imagecreatefromgif($tempname);
$height_orig = $size[1];
$width_orig = $size[0];
$width = 100;
$height = intval($height_orig*$width/$width_orig);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
$newImg = imagecreatetruecolor($width, $height);
imagecopyresampled($newImg, $im_temp, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagegif($newImg, "$tempname", 100);
move_uploaded_file($tempname,"thumb/thumb_$dat$name");
}
if($size[2]==2)
{
$im_temp = imagecreatefromjpeg($tempname);
$height_orig = $size[1];
$width_orig = $size[0];
$width = 100;
$height = intval($height_orig*$width/$width_orig);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
$newImg = imagecreatetruecolor($width, $height);
imagecopyresampled($newImg, $im_temp, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($newImg, "$tempname", 100);
move_uploaded_file($tempname,"thumb/thumb_$dat$name");
}
if($size[2]==3)
{
$im_temp = imagecreatefrompng($tempname);
$height_orig = $size[1];
$width_orig = $size[0];
$width = 100;
$height = intval($height_orig*$width/$width_orig);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
$newImg = imagecreatetruecolor($width, $height);
imagecopyresampled($newImg, $im_temp, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($newImg, "$tempname", 100);
move_uploaded_file($tempname,"thumb/thumb_$dat$name");
}
}
else
{
echo 'Datei #' . $i . ' =>Upload-Fehler:#'.
$_FILES['file']['error'][$i] . '<br>';
}
}
}
}
?>