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:
|
//Ordner für die Bilder
$picdir ='include/images/gallery/usergallery/';
$picdir2 ='include/images/gallery/usergallery/thumbs/';
//Neuer Name für die Bilder
$newname = time();
$name = time();
$thumbname = time();
settype($newname, "string");
settype($name, "string");
settype($thumbname, "string");
$newname = $newname.'.jpg';
$name = $name;
$thumbname = $thumbname.'-thumb.jpg';
//Neuer Pfad+Bildname
$new_path = $picdir.$newname;
// altes Bild erst löschen
include("include/includes/frs3de78q.php");
$db = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS)
or die ("Database problem. Please try again".mysql_error());
mysql_select_db("user_bild",$db)
or die ("Database problem. Please try again".mysql_error());
$filename_SQL="SELECT filename FROM user_daten WHERE username='$username'";
$filename_result=mysql_query($filename_SQL);
$filename=mysql_fetch_array($filename_result);
$delete_file=$filename['filename'].'.jpg';
$delete_file2=$filename['filename'].'-thumb.jpg';
$delete_bild=$picdir.$delete_file;
$delete_bild2=$picdir2.$delete_file2;
unlink($delete_bild);
unlink($delete_bild2);
//Originalbild verschieben
move_uploaded_file($_FILES['new_bild']['tmp_name'],$new_path);
/* Thumbnail erstellen */
$imagefile = $new_path;
$imagesize = getimagesize($imagefile);
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
$imagetype = $imagesize[2];
switch ($imagetype) {
case 2: // JPEG
$image = imagecreatefromjpeg($imagefile);
break;
default:
die('Unsupported imageformat');
}
// Maximalausmaße
$maxthumbwidth = 140;
$maxthumbheight = 140;
$width = @imagesx($image);
$height = @imagesy($image);
// Ausmaße kopieren, wir gehen zuerst davon aus, dass das Bild schon Thumbnailgröße hat
$thumbwidth = $imagewidth;
$thumbheight = $imageheight;
// Breite skalieren falls nötig
if ($thumbwidth > $maxthumbwidth) {
$factor = $maxthumbwidth / $thumbwidth;
$thumbwidth *= $factor;
$thumbheight *= $factor;
}
// Höhe skalieren, falls nötig
if ($thumbheight > $maxthumbheight) {
$factor = $maxthumbheight / $thumbheight;
$thumbwidth *= $factor;
$thumbheight *= $factor;
}
// Thumbnail erstellen
$newim = @ImageCreateTrueColor($thumbwidth, $thumbheight);
@ImageCopyresampled($newim, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $width, $height);
ob_start();
if($imagetype=="1") {@imagegif ($newim);}
if($imagetype=="2") {@imagejpeg ($newim);}
if($imagetype=="3") {@imagepng ($newim);}
@imagedestroy($newim);
$image = ob_get_contents();
ob_end_clean();
$picthumb ='include/images/gallery/usergallery/thumbs/'.$thumbname;
$fp = fopen($picthumb, 'wb');
fwrite($fp, $image);
fclose($fp);
@chmod ($picthumb, 0777);
$filename_date = date("d.m.Y H:i");
|